/*

Understanding Child Sex Trafficking Using Victim-Level Data: 		    Replication

*/


clear all
graph drop _all
set more off
set maxvar 32767
ssc install psmatch2, replace


*** ----------------------------------------------------------------------
**# 						 0. Defining globals
*** ----------------------------------------------------------------------

***** Insert your path here
if c(username) == "hp" {
	global traffick_repl_local "C:/Users/hp/Dropbox/Paper_Traffick/Replication package"
}
else{
	global traffick_repl_local "/Users/alla/Dropbox/Paper_Traffick/Replication package/"
}

cd "$traffick_repl_local"

run "$traffick_repl_local/ado/xtsum3.ado"

*** ----------------------------------------------------------------------
**# 						 Main Analysis 
*** ----------------------------------------------------------------------

*** ----------------------------------------------------------------------
**## 						 Table 1 
*** ----------------------------------------------------------------------

cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear

	global C "edu aboveprimary abovesecondary urban pc1_assets_new electricity"
	
		* Trafficked (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if tv2==1 
			local mean_traff_`ll' = r(mean) 
			local sd_traff_`ll' = r(sd) 
			local N_traff_`ll' = r(N)  
			local mean_traff_`ll' : di %8.2f `mean_traff_`ll''
			local sd_traff_`ll' : di %8.2f `sd_traff_`ll''			
			local ll = `ll'+1
			}
			di `mean_traff_1'
			
		* Not trafficked in shelters (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if  tv2==0 & shelter==1  
			local mean_sh_`ll' = r(mean) 
			local sd_sh_`ll' = r(sd) 
			local N_sh_`ll' = r(N)  
			local mean_sh_`ll' : di %8.2f `mean_sh_`ll''
			local sd_sh_`ll' : di %8.2f `sd_sh_`ll''			
			local ll = `ll'+1
			}
			
		* Trafficked vs not trafficked in shelters (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' tv2 if analysis1==1  
			local N_regsh_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue_sh_`ll'  = rtable[4,1] 
			local pvalue_sh_`ll' : di %8.3f `pvalue_sh_`ll''
			local ll = `ll'+1
			}
		
	foreach weight in weight_prov_2y  {
	
		* Not trafficked in DHS (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if tv2==0 & analysis2_2008==1 & `weight'!=. [aweight=wgt] 
			local mean_`weight'_`ll' = r(mean) 
			local sd_`weight'_`ll' = r(sd) 
			local N_`weight'_`ll' = r(N)  
			local mean_`weight'_`ll' : di %8.2f `mean_`weight'_`ll''
			local sd_`weight'_`ll' : di %8.2f `sd_`weight'_`ll''			
			local ll = `ll'+1
			}
			
		* Trafficked vs not trafficked in DHS (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' tv2 if tv2==1 | (analysis2_2008==1 & `weight'!=.) [pweight=wgt]
			local N_reg1_`weight'_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue_`weight'_`ll' = rtable[4,1] 
			local pvalue_`weight'_`ll' : di %8.3f `pvalue_`weight'_`ll''
			local ll = `ll'+1
			}
			
		* Not trafficked in shelters vs not trafficked in DHS (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' analysis1 if (tv2==0 & shelter==1) | (tv2==0 & analysis2_2008==1 & `weight'!=.) [pweight=wgt] 
			local N_reg2_`weight'_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue2_`weight'_`ll' = rtable[4,1] 
			local pvalue2_`weight'_`ll' : di %8.3f `pvalue2_`weight'_`ll''
			local ll = `ll'+1
			}
	
		* Table
		
		cap file close soutput
		file open soutput using "output/tables/Table1.tex", write replace
		file write soutput "\begin{sidewaystable}[htbp] \centering \footnotesize \caption{Socioeconomic background} \begin{threeparttable}\begin{tabular}{l | c c c | c c c | c c c | c | c | c} \hline\hline"  _n
		file write soutput " &\multicolumn{3}{c|}{Trafficked} &\multicolumn{3}{c|}{\makecell{Not trafficked \\ in shelters}} &\multicolumn{3}{c|}{DHS sample} &\multicolumn{1}{c|}{\makecell{Trafficked vs. not \\ trafficked in shelters}} &\multicolumn{1}{c|}{\makecell{Trafficked vs. \\ DHS sample}} &\multicolumn{1}{c}{\makecell{Not trafficked in shelters \\ vs. DHS sample}}  \\" _n
		file write soutput "& \multicolumn{3}{c|}{(1)}  & \multicolumn{3}{c|}{(2)} & \multicolumn{3}{c|}{(3)} & \multicolumn{1}{c|}{(4)} & \multicolumn{1}{c|}{(5)}  &  \multicolumn{1}{c}{(6)} \\" _n
		file write soutput "  & \textit{Mean} & \textit{SD}  & \textit{Obs.} & \textit{Mean} & \textit{SD} & \textit{Obs.} & \textit{Mean} & \textit{SD} & \textit{Obs.} & \textit{p-value} & \textit{p-value} & \textit{p-value}\\ "_n
		file write soutput "\hline" _n
	
		file write soutput "Years of education & `mean_traff_1' & `sd_traff_1' & `N_traff_1' & `mean_sh_1' & `sd_sh_1' & `N_sh_1' & `mean_`weight'_1' & `sd_`weight'_1' & `N_`weight'_1' & `pvalue_sh_1' & `pvalue_`weight'_1' &  `pvalue2_`weight'_1' \\" _n
		file write soutput "Above primary education & `mean_traff_2' & `sd_traff_2' & `N_traff_2' & `mean_sh_2' & `sd_sh_2' & `N_sh_2' & `mean_`weight'_2' & `sd_`weight'_2' & `N_`weight'_2' & `pvalue_sh_2' & `pvalue_`weight'_2' &  `pvalue2_`weight'_2' \\" _n
		file write soutput "Above secondary education & `mean_traff_3' & `sd_traff_3' & `N_traff_3' & `mean_sh_3' & `sd_sh_3' & `N_sh_3' & `mean_`weight'_3' & `sd_`weight'_3' & `N_`weight'_3' & `pvalue_sh_3' & `pvalue_`weight'_3' &  `pvalue2_`weight'_3' \\" _n
		file write soutput "Urban & `mean_traff_4' & `sd_traff_4' & `N_traff_4' & `mean_sh_4' & `sd_sh_4' & `N_sh_4' & `mean_`weight'_4' & `sd_`weight'_4' & `N_`weight'_4' & `pvalue_sh_4' & `pvalue_`weight'_4' &  `pvalue2_`weight'_4' \\" _n
		file write soutput "Assets & `mean_traff_5' & `sd_traff_5' & `N_traff_5' & `mean_sh_5' & `sd_sh_5' & `N_sh_5' & `mean_`weight'_5' & `sd_`weight'_5' & `N_`weight'_5' & `pvalue_sh_5' & `pvalue_`weight'_5' &  `pvalue2_`weight'_5' \\" _n
		file write soutput "Access to electricity & `mean_traff_6' & `sd_traff_6' & `N_traff_6' & `mean_sh_6' & `sd_sh_6' & `N_sh_6' & `mean_`weight'_6' & `sd_`weight'_6' & `N_`weight'_6' & `pvalue_sh_6' & `pvalue_`weight'_6' &  `pvalue2_`weight'_6' \\" _n
	
		file write soutput "\hline\hline" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} For DHS data, only the 2008 file is used and it includes sampling weights. Matches are done by province and by year of birth within a 3-year span. Columns (4), (5) and (6) provide results from a t-test of the difference in means respectively between columns (1) and (2), columns (1) and (3), and columns (2) and (3). Assets are measured through an index that captures ownership of durable goods. This index uses the first principal component of the following assets, where loading factors are included in parentheses: bicycle (0.51), car (0.52), motorcycle (0.54), radio (0.13), refrigerator (0.28), television (0.28).  \end{tablenotes} \end{threeparttable} \end{sidewaystable}"
		file close soutput	
	}
	
*** ----------------------------------------------------------------------
**## 						 Table 2
*** ----------------------------------------------------------------------

cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear	


		local ll = 1
		foreach var in hhsize sibtot sisters oldersis youngersis livedwithmoth livedwithfath bothbirthparents diffidealgirls1998 order1998 {
			reg `var' tv2 i.dhsregion if sisters!=. & analysis1==1  , ro  
			local beta_c1_r = _b[tv2]
			local sigma_c1_r = _se[tv2]
			local beta_c1_r`ll' : di %8.3f `beta_c1_r'
			local sigma_c1_r`ll' : di %8.3f `sigma_c1_r'
			matrix rtable = r(table)
			local pvalue  = rtable[4,1] 
			local star_c1_r`ll' = ""
				if `pvalue' < 0.1 local star_c1_r`ll'= "*" 
				if `pvalue' < 0.05 local star_c1_r`ll' = "**" 
				if `pvalue' < 0.01 local star_c1_r`ll' = "***" 
			local N_c1_r`ll' = e(N)
			su `var' if e(sample)==1 & tv2==0
			local mcontrol_c1_r = r(mean)
			local mcontrol_c1_r`ll' : di %8.3f `mcontrol_c1_r'
			
			local ll = `ll'+1
		}
	
		* DHS control group (no weights) : loop for type of match
		
		foreach weight in  weight_prov_2y  {
			local ll = 1
			foreach var in hhsize sibtot sisters oldersis youngersis livedwithmoth livedwithfath bothbirthparents diffidealgirls1998 order1998 {
				reg `var' tv2 i.dhsregion if sisters!=. & analysis2_2008==1 & `weight'!=. [pweight=wgt], ro   
				local beta_c`weight'_r = _b[tv2]
				local sigma_c`weight'_r = _se[tv2]
				local beta_c`weight'_r`ll' : di %8.3f `beta_c`weight'_r'
				local sigma_c`weight'_r`ll' : di %8.3f `sigma_c`weight'_r'
				matrix rtable = r(table)
				local pvalue  = rtable[4,1] 
				local star_c`weight'_r`ll' = ""
					if `pvalue' < 0.1 local star_c`weight'_r`ll'= "*" 
					if `pvalue' < 0.05 local star_c`weight'_r`ll' = "**" 
					if `pvalue' < 0.01 local star_c`weight'_r`ll' = "***" 
				local N_c`weight'_r`ll' = e(N)
				su `var' if e(sample)==1 & tv2==0
				local mcontrol_c`weight'_r = r(mean)
				local mcontrol_c`weight'_r`ll' : di %8.3f `mcontrol_c`weight'_r'
			
				local ll = `ll'+1
			}
		}

		* Table
		
		cap file close soutput
		file open soutput using "output/tables/Table2.tex", write replace
		file write soutput "\begin{table}[htbp] \centering \scriptsize \caption{Household composition} \begin{threeparttable} \begin{tabular}{lcccccc} \\[-1.8ex] \hline\hline \\[-1.8ex]"  _n
		file write soutput "& \multicolumn{3}{c}{Comparison with not trafficked in shelters} & \multicolumn{3}{c}{Comparison with DHS sample}\\" _n
		file write soutput "\\[-1.8ex] \cmidrule(r){2-4} \cmidrule(l){5-7}  \\[-1.8ex]" _n
		file write soutput "& (1) & (2) & (3) & (4) & (5) & (6) \\   " _n
		file write soutput "  \textit{Dependent variables:}  & Trafficked (OLS)  & Not trafficked (mean) & Obs. & Trafficked (OLS)  & Not trafficked (mean) & Obs.\\ "_n
		file write soutput "\\[-1.8ex]\hline\\[-1.8ex]"
		
		file write soutput "Household size & `beta_c1_r1'`star_c1_r1' & `mcontrol_c1_r1' & `N_c1_r1' & `beta_cweight_prov_2y_r1'`star_cweight_prov_2y_r1' & `mcontrol_cweight_prov_2y_r1' & `N_cweight_prov_2y_r1'\\" _n
		file write soutput "& (`sigma_c1_r1') & & & (`sigma_cweight_prov_2y_r1')\\ " _n
		file write soutput "Number of siblings & `beta_c1_r2'`star_c1_r2' & `mcontrol_c1_r2' & `N_c1_r2' & `beta_cweight_prov_2y_r2'`star_cweight_prov_2y_r2' & `mcontrol_cweight_prov_2y_r2' & `N_cweight_prov_2y_r2'\\" _n
		file write soutput "& (`sigma_c1_r2') & & & (`sigma_cweight_prov_2y_r2')\\ " _n
		file write soutput "Number of sisters & `beta_c1_r3'`star_c1_r3' & `mcontrol_c1_r3' & `N_c1_r3' & `beta_cweight_prov_2y_r3'`star_cweight_prov_2y_r3' & `mcontrol_cweight_prov_2y_r3' & `N_cweight_prov_2y_r3'\\" _n
		file write soutput "& (`sigma_c1_r3') & & & (`sigma_cweight_prov_2y_r3')\\ " _n
		file write soutput "Number of older sisters & `beta_c1_r4'`star_c1_r4' & `mcontrol_c1_r4' & `N_c1_r4' & `beta_cweight_prov_2y_r4'`star_cweight_prov_2y_r4' & `mcontrol_cweight_prov_2y_r4' & `N_cweight_prov_2y_r4'\\" _n
		file write soutput "& (`sigma_c1_r4') & & & (`sigma_cweight_prov_2y_r4')\\ " _n
		file write soutput "Number of younger sisters & `beta_c1_r5'`star_c1_r5' & `mcontrol_c1_r5' & `N_c1_r5' & `beta_cweight_prov_2y_r5'`star_cweight_prov_2y_r5' & `mcontrol_cweight_prov_2y_r5' & `N_cweight_prov_2y_r5'\\" _n
		file write soutput "& (`sigma_c1_r5') & & & (`sigma_cweight_prov_2y_r5')\\ " _n
		file write soutput "Lived with birth mother & `beta_c1_r6'`star_c1_r6' & `mcontrol_c1_r6' & `N_c1_r6' & `beta_cweight_prov_2y_r6'`star_cweight_prov_2y_r6' & `mcontrol_cweight_prov_2y_r6' & `N_cweight_prov_2y_r6'\\" _n
		file write soutput "& (`sigma_c1_r6') & & & (`sigma_cweight_prov_2y_r6')\\ " _n
		file write soutput "Lived with birth father & `beta_c1_r7'`star_c1_r7' & `mcontrol_c1_r7' & `N_c1_r7' & `beta_cweight_prov_2y_r7'`star_cweight_prov_2y_r7' & `mcontrol_cweight_prov_2y_r7' & `N_cweight_prov_2y_r7'\\" _n
		file write soutput "& (`sigma_c1_r7') & & & (`sigma_cweight_prov_2y_r7')\\ " _n
		file write soutput "Lived with both birth parents & `beta_c1_r8'`star_c1_r8' & `mcontrol_c1_r8' & `N_c1_r8' & `beta_cweight_prov_2y_r8'`star_cweight_prov_2y_r8' & `mcontrol_cweight_prov_2y_r8' & `N_cweight_prov_2y_r8'\\" _n
		file write soutput "& (`sigma_c1_r8') & & & (`sigma_cweight_prov_2y_r8')\\ " _n
		file write soutput "Deviation from ideal no. of girls & `beta_c1_r9'`star_c1_r9' & `mcontrol_c1_r9' & `N_c1_r9' & `beta_cweight_prov_2y_r9'`star_cweight_prov_2y_r9' & `mcontrol_cweight_prov_2y_r9' & `N_cweight_prov_2y_r9'\\" _n
		file write soutput "& (`sigma_c1_r9') & & & (`sigma_cweight_prov_2y_r9')\\ " _n
		file write soutput "Respondent's birth order higher & `beta_c1_r10'`star_c1_r10' & `mcontrol_c1_r10' & `N_c1_r10' & `beta_cweight_prov_2y_r10'`star_cweight_prov_2y_r10' & `mcontrol_cweight_prov_2y_r10' & `N_cweight_prov_2y_r10'\\" _n
		file write soutput "than ideal no. of girls & (`sigma_c1_r10') & & & (`sigma_cweight_prov_2y_r10')\\ " _n

	
		file write soutput "\\[-1.8ex]\hline\hline\\[-1.8ex]" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} Columns 1 and 4 report the results of an OLS regression of each dependent variable on the trafficked status, with observations in Column 3 and 6: each coefficient is the result of a different regression. Columns 2 and 5 report the mean of each dependent variable in the corresponding comparison group. For all specifications, region fixed effects are included. There are no other controls. For each dependent variable (in rows), a first specification is estimated comparing trafficked victims with non-trafficked girls in shelters, and another one comparing them with girls in the 2008 DHS survey. For DHS data, only observations matching victims' provinces and years of birth (within a 3-year span) are kept. Robust standard errors in parentheses. *, ** and *** indicate significance at the 10, 5, 1\% levels." _n
		file write soutput "\end{tablenotes} \end{threeparttable} \end{table}"
		file close soutput	
		
		

*** ----------------------------------------------------------------------
**## 						 Table 3 
*** ----------------------------------------------------------------------

cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear

	lab var spei12 "$\Delta$ SPEI"
	lab var spei12sq "$\Delta$ SPEI sq."
	lab var spei12_pos "Positive $\Delta$ SPEI"
	lab var spei12_neg "Negative $\Delta$ SPEI"

	global C "urban pc1_assets_new pc1_assets_new_sq sibtot sisters oldersis mother_alive father_alive alivemissing"
		
	eststo shock0: reg tv2 spei12 $C i.q102b, ro  
	eststo shock0_no: reg tv2 spei12 i.q102b if e(sample)==1, ro
	eststo shock1: reg tv2 spei12 spei12sq $C i.q102b, ro  
	estadd local controls "\checkmark" 
	estadd local regionFE "\checkmark" 
	eststo shock1_no: reg tv2 spei12 spei12sq i.q102b if e(sample)==1, ro
	estadd local controls "$\times$" 
	estadd local regionFE "\checkmark" 
	eststo shock2: reg tv2 spei12_pos spei12_neg $C i.q102b, ro 
	estadd local controls "\checkmark"
	estadd local regionFE "\checkmark" 
	eststo shock2_no: reg tv2 spei12_pos spei12_neg i.q102b if e(sample)==1, ro 
	estadd local controls "$\times$"
	estadd local regionFE "\checkmark" 

	esttab shock1_no shock1 shock2_no shock2 using "output/tables/Table3.tex", ///
	title(Weather shocks and trafficking ) ///
	k(spei12 spei12sq spei12_pos spei12_neg ) ///
	label cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) noconstant ///
	stats(controls regionFE r2  N, fmt(%9.0g %9.0g %9.3f %9.0g) labels(Controls RegionFE R$^2$ Observations)) eqlabels(none) style(tex) replace
	estimates drop _all
		

*** ----------------------------------------------------------------------
**## 						 Table 4
*** ----------------------------------------------------------------------

cd "$traffick_repl_local"
use "$traffick_repl_local/input/Trafficking_replication.dta", clear


	local ll = 1
	foreach var in girl_leaving firstleaver marriedfor_hh backtosch_hh sendmoney_hh {
		xi: reg `var' tv2 i.q102b, ro 
		local beta_c1_r = _b[tv2]
		local sigma_c1_r = _se[tv2]
		local beta_c1_r`ll' : di %8.3f `beta_c1_r'
		local sigma_c1_r`ll' : di %8.3f `sigma_c1_r'
		matrix rtable = r(table)
		local pvalue  = rtable[4,1] 
		local star_c1_r`ll' = ""
			if `pvalue' < 0.1 local star_c1_r`ll'= "*" 
			if `pvalue' < 0.05 local star_c1_r`ll' = "**" 
			if `pvalue' < 0.01 local star_c1_r`ll' = "***" 
		local N_c1_r`ll' = e(N)
		su `var' if e(sample)==1 & tv2==0
		local mcontrol_c1_r = r(mean)
		local mcontrol_c1_r`ll' : di %8.3f `mcontrol_c1_r'
			
		local ll = `ll'+1
	}

		cap file close soutput
		file open soutput using "output/tables/Table4.tex", write replace
		file write soutput "\begin{table}[htbp] \centering \caption{Expectations prior to leaving the household} \begin{threeparttable} \begin{tabular}{lccc} \\[-1.8ex] \hline\hline \\[-1.8ex]"  _n
		file write soutput "& (1) & (2) & (3)  \\   " _n
		file write soutput "  \textit{Dependent variables:}  & Trafficked (OLS)  & Not trafficked (mean) & Obs. \\ "_n
		file write soutput "\\[-1.8ex]\hline\\[-1.8ex]" _n
	
		file write soutput "Personally knew a girl who left village & `beta_c1_r1'`star_c1_r1' & `mcontrol_c1_r1' & `N_c1_r1' \\" _n
		file write soutput "& (`sigma_c1_r1') &\\ " _n
		file write soutput "First to leave household & `beta_c1_r2'`star_c1_r2' & `mcontrol_c1_r2' & `N_c1_r2' \\" _n
		file write soutput "& (`sigma_c1_r2') &\\ " _n
		file write soutput "Likelihood of marrying a foreign man (\%) & `beta_c1_r3'`star_c1_r3' & `mcontrol_c1_r3' & `N_c1_r3' \\" _n
		file write soutput "& (`sigma_c1_r3') &\\ " _n
		file write soutput "Likelihood of going back to school (\%) & `beta_c1_r4'`star_c1_r4' & `mcontrol_c1_r4' & `N_c1_r4' \\" _n
		file write soutput "& (`sigma_c1_r4') &\\ " _n
		file write soutput "Likelihood of sending money home (\%) & `beta_c1_r5'`star_c1_r5' & `mcontrol_c1_r5' & `N_c1_r5' \\" _n
		file write soutput "& (`sigma_c1_r5') &\\ " _n

		file write soutput "\\[-1.8ex]\hline\hline\\[-1.8ex]" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} Column 1 reports the results of an OLS regression of each dependent variable on the trafficked status and each row is the result of a different regression. Column 2 reports the mean of each dependent variable in the non-trafficked sub-group. The estimations include region fixed effects, but no other controls. Robust standard errors are in parentheses. *, ** and *** indicate significance at the 10, 5, 1\% levels."_n
		file write soutput "\end{tablenotes} \end{threeparttable} \end{table}"
		file close soutput	
		
*** ----------------------------------------------------------------------
**## 						 Table 5
*** ----------------------------------------------------------------------

cd "$traffick_repl_local"
use "$traffick_repl_local/input/Trafficking_replication.dta", clear


	estpost summarize howfound_family howfound_friend howfound_recruiter howfound_other  ///
					advancepayment familyjob ///
					lastjob_dancer lastjob_entertainer lastjob_freelance lastjob_sexworker lastjob_waitress lastjob_other  diff_jobexpect ///
					supervised timelastjob nightsperwk ///
					q312 marriedfor gotpreg gotill  ///
					wage indebt indebt_amt
		est sto sum1
		esttab sum1 using "output/tables/Table5.tex", ///
		title(Experience of trafficking victims) ///
		cells("count(fmt(%9.0f)) mean(fmt(%9.3f)) sd(fmt(%9.3f)) ") ///
		style(tex) label nonote noobs replace 
		
		
		
*** ----------------------------------------------------------------------
**## 						 Table 6
*** ----------------------------------------------------------------------

cd "$traffick_repl_local"
use "$traffick_repl_local/input/Trafficking_replication.dta", clear


	local ll = 1
	foreach var in hn_q504_amount_required discount  hn_q505_sure_amount riskcoef risk impulse  confident conform contactfamily wantchild tn_expectwage {
		xi: reg `var' tv2 i.q102b, ro 
		local beta_c1_r = _b[tv2]
		local sigma_c1_r = _se[tv2]
		local beta_c1_r`ll' : di %8.3f `beta_c1_r'
		local sigma_c1_r`ll' : di %8.3f `sigma_c1_r'
		matrix rtable = r(table)
		local pvalue  = rtable[4,1] 
		local star_c1_r`ll' = ""
			if `pvalue' < 0.1 local star_c1_r`ll'= "*" 
			if `pvalue' < 0.05 local star_c1_r`ll' = "**" 
			if `pvalue' < 0.01 local star_c1_r`ll' = "***" 
		local N_c1_r`ll' = e(N)
		su `var' if e(sample)==1 & tv2==0
		local mcontrol_c1_r = r(mean)
		local mcontrol_c1_r`ll' : di %8.3f `mcontrol_c1_r'
			
		local ll = `ll'+1
	}

		cap file close soutput
		file open soutput using "output/tables/Table6.tex", write replace
		file write soutput "\begin{table}[htbp] \centering  \caption{Preferences and expectations by trafficking status} \begin{threeparttable} \begin{tabular}{lccc} \\[-1.8ex] \hline\hline \\[-1.8ex]"  _n
		file write soutput "& (1) & (2) & (3)  \\   " _n
		file write soutput "  \textit{Dependent variables:}  & Trafficked (OLS)  & Not trafficked (mean) & Observations \\ "_n
		file write soutput "\\[-1.8ex]\hline\\[-1.8ex]" _n
	
		file write soutput "Amount in 5wks (hundreds PHP)$^a$ & `beta_c1_r1'`star_c1_r1' & `mcontrol_c1_r1' & `N_c1_r1' \\" _n
		file write soutput "& (`sigma_c1_r1') &\\ " _n
		file write soutput "Discount rate & `beta_c1_r2'`star_c1_r2' & `mcontrol_c1_r2' & `N_c1_r2' \\" _n
		file write soutput "& (`sigma_c1_r2') &\\ " _n
		file write soutput "Sure amount (hundreds PHP)$^b$ & `beta_c1_r3'`star_c1_r3' & `mcontrol_c1_r3' & `N_c1_r3' \\" _n
		file write soutput "& (`sigma_c1_r3') &\\ " _n
		file write soutput "Risk coefficient & `beta_c1_r4'`star_c1_r4' & `mcontrol_c1_r4' & `N_c1_r4' \\" _n
		file write soutput "& (`sigma_c1_r4') &\\ " _n
		file write soutput "Willingness to take risks (self-reported) & `beta_c1_r5'`star_c1_r5' & `mcontrol_c1_r5' & `N_c1_r5' \\" _n
		file write soutput "& (`sigma_c1_r5') &\\ " _n
		file write soutput "Impulsiveness (self-reported) & `beta_c1_r6'`star_c1_r6' & `mcontrol_c1_r6' & `N_c1_r6' \\" _n
		file write soutput "& (`sigma_c1_r6') &\\ " _n
		file write soutput "Confidence (self-reported) & `beta_c1_r7'`star_c1_r7' & `mcontrol_c1_r7' & `N_c1_r7' \\" _n
		file write soutput "& (`sigma_c1_r7') &\\ " _n
		file write soutput "Importance of conforming to expectations (self-reported) & `beta_c1_r8'`star_c1_r8' & `mcontrol_c1_r8' & `N_c1_r8' \\" _n
		file write soutput "& (`sigma_c1_r8') &\\ " _n
		file write soutput "Has contact with family & `beta_c1_r9'`star_c1_r9' & `mcontrol_c1_r9' & `N_c1_r9' \\" _n
		file write soutput "& (`sigma_c1_r9') &\\ " _n
		file write soutput "Wants children & `beta_c1_r10'`star_c1_r10' & `mcontrol_c1_r10' & `N_c1_r10' \\" _n
		file write soutput "& (`sigma_c1_r10') &\\ " _n
		file write soutput "Expected wage in next job (thousands PHP) & `beta_c1_r11'`star_c1_r11' & `mcontrol_c1_r11' & `N_c1_r11' \\" _n
		file write soutput "& (`sigma_c1_r11') &\\ " _n

		file write soutput "\\[-1.8ex]\hline\hline\\[-1.8ex]" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:}  Column 1 reports the results of an OLS regression of each dependent variable on trafficked. Column 2 reports the mean of each dependent variable in the non-trafficked sample. The estimations include region fixed effects, but no other controls. *, ** and *** indicate significance at the 10, 5, 1\% levels.\\ $^{a}$ Amount in 5wks (PHP) is the respondent's preferred sum to receive in five weeks' time instead of 500PHP in one week's time.\\ $^{b}$ Sure amount (PHP) is the sum a respondent would like to receive with certainty instead of choosing to participate in a lottery game that yields 0PHP with a probability of 50\% and 500PHP with a probability of 50\%. \end{tablenotes} \end{threeparttable} \end{table}"
		file close soutput
		
		


*** ----------------------------------------------------------------------
**# 						Appendix
*** ----------------------------------------------------------------------

*** ----------------------------------------------------------------------
**## 						Figure A1
*** ----------------------------------------------------------------------

cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear

		collapse (mean) spei12, by(rain_y)
		line spei12 rain_y, ytitle("Average SPEI index (12 months)") xtitle("Year")
		graph export "output/graphs/FigureA1.png", as(png) replace


*** ----------------------------------------------------------------------
**## 						Figure A2
*** ----------------------------------------------------------------------

				
cd "$traffick_repl_local"


use "$traffick_repl_local/input/Trafficking_replication.dta", clear

		global C "urban pc1_assets_new pc1_assets_new_sq sibtot sisters oldersis mother_alive father_alive alivemissing"

		reg tv2 spei12_pos spei12_neg i.q102b $C, ro
		distinct q102a if e(sample)==1
		levelsof q102a if e(sample)==1, local(villages) 



use "$traffick_repl_local/input/rainfall_replication.dta", clear

			* Only keep villages and years that are in the regression sample (filling in the gaps in years)
			
			gen villageOK = 0
				foreach n of local villages {
				replace villageOK = 1 if (q102a =="`n'")
				}
			keep if villageOK==1
			keep if rain_y>1977 & rain_y<2010
		
		
		collapse (mean) spei12, by(q102a)

		gen prov_id = .
		replace prov_id = 2 if q102a == "Agusan_Norte" | q102a == "Butuan"
		replace prov_id = 3 if q102a == "Agusan_Sur"
		replace prov_id = 12 if q102a == "Sugod" | q102a == "Talisay_Batangas"
		replace prov_id = 15 if q102a == "Bohol" | q102a == "Carmen" | q102a == "Estaka" | q102a == "San_Isidro"
		replace prov_id = 16 if q102a == "Bukidnon" | q102a == "Malaybalay"
		replace prov_id = 17 if q102a == "Bagong_Silang" | q102a == "Bocaue" | q102a == "Caloocan"
		replace prov_id = 18 if q102a == "Cagayan_de_Oro"
		replace prov_id = 21 if q102a == "Camiguin"
		replace prov_id = 24 if q102a == "Martires"
		global prov "Adlawon Alegria Aloguinsan Argao Badian Bagatayam Balamban Bantayan Barili Basak Bogo Boljoon Borbon Bulacao Capitol_Site Carcar Carreta Catmon Cebu Consolacion Daanbantayan Dalaguete Danao Duljo_Fatima Dumanjug Inayagan Inayawan Lahug Lapu_Lapu Libo Lorega Lutac Mactan Malabuyoc Malapascua Mambaling Mandaue Minglanilla Moalboal Naga Oslob Pardo Pasil Pasilagon Payahan_Guba Pinamungahan Pooc Pulangbato San_Fernando San_Remigio Santander Siraw Sunny_Hills Tabuelan Takan Talamban_Cebu Talisay_Cebu Tejero Toledo Tuboran Compostela"
		foreach x in $prov{
			replace prov_id = 25 if q102a =="`x'"
		}		
		replace prov_id = 24 if q102a == "Cotabato"
		replace prov_id = 28 if q102a == "Tagum_Davao"
		replace prov_id = 29 if q102a == "Davao" | q102a == "Mindanao"
		replace prov_id = 31 if q102a == "Lawaan"
		replace prov_id = 34 if q102a == "Laoag_City"
		replace prov_id = 36 if q102a == "Iloilo"
		replace prov_id = 43 if q102a == "Leyte" | q102a == "Tacloban"
		replace prov_id = 48 if q102a == "Ozamiz"
		replace prov_id = 49 if q102a == "Lagonglong" | q102a == "Lapasan"
		replace prov_id = 51 if q102a == "Cadiz" | q102a == "Negros" | q102a == "San_Carlos"
		replace prov_id = 52 if q102a == "Dumaguete" | q102a == "Negros_Oriental"
		replace prov_id = 65 if q102a == "Calatrava"
		replace prov_id = 66 if q102a == "Samar"
		replace prov_id = 81 if q102a == "Labangan" | q102a == "Pagadian" | q102a == "Zamboanga"
		replace prov_id = 69 if q102a == "Carbon"
		replace prov_id = 40 if q102a == "Silangan" | q102a=="S�langan"
		replace prov_id = 41 if q102a == "Tubod"
		

		collapse (mean) spei12, by(prov_id)	
		tempfile spei_prov
		save "`spei_prov'"
			
				
cd "$traffick_repl_local/input/"

			* Province boundaries (shapefile) 
			shp2dta using "$traffick_repl_local/input/gadm41_PHL_1.shp", ///
				database(db) coordinates(coord) genid(prov_id) replace
			* Country boundaries 
			shp2dta using "$traffick_repl_local/input/gadm41_PHL_0.shp", ///
				database(phdb) coordinates(phcoord) genid(id) replace
		 
use db, clear

			merge 1:1 prov_id using "`spei_prov'"
			drop if _m != 3

			format spei12 %4.2f
			
			spmap spei12 using coord, id(prov_id) fcolor(Greens) polygon(data(phcoord))  ///
							 clnumber(6)
							 
			cd "$traffick_repl_local/"	
			
			graph export "output/graphs/FigureA2.pdf", as(pdf) replace


	
*** ----------------------------------------------------------------------
**## 						Figure A3
*** ----------------------------------------------------------------------
				
cd "$traffick_repl_local"


use "$traffick_repl_local/input/Trafficking_replication.dta", clear

	keep if shelter == 1


	*** In matrix M we will store the means for T group, means for control groups, p-value on the test of equality of the two means/sd


	mat M = J(7, 18,.)
	mat rownames M = urban  pc1_assets_new  sibtot  sisters oldersis mother_alive father_alive

	*** In matrix K we will store standadized difference in means for key covariates calculated as (mean for T - mean for C)/sd(overall sample)

	mat K = J(7,6,.)
	mat rownames K = urban  pc1_assets_new  sibtot  sisters oldersis mother_alive father_alive

	*** Unadjusted


	loc i = 1 

	foreach var of varlist urban  pc1_assets_new  sibtot  sisters oldersis mother_alive father_alive{
		
		ttest `var', by(tv2) 

		matrix M[`i', 1] = r(mu_2)
		matrix M[`i', 2] = r(mu_1)
		matrix M[`i', 3] = r(p)
		local mu1 = r(mu_1)
		local mu2 = r(mu_2)
		local sd = r(sd)

		matrix K[`i',1] = (`mu2' - `mu1')/`sd'
		
		loc i= `i' +1
	}

	*** Mahalanobis distance matching

	psmatch2 tv2, mahalanobis(urban  pc1_assets_new  sibtot  sisters oldersis mother_alive father_alive)  


	svyset [pw=_weight]


		svy: mean urban, over(tv2) coeflegend 


		mat M[1, 4] = _b[c.urban@1bn.tv2]
		mat M[1, 5] = _b[c.urban@0bn.tv2]
		lincom _b[c.urban@0bn.tv2] - _b[c.urban@1bn.tv2]
		loc mean_t = _b[c.urban@1bn.tv2]
		loc mean_c = _b[c.urban@0bn.tv2]
		return list 
		mat M[1, 6] = r(p)
		svy: mean urban 
		estat sd
		matrix K[1,2] = (`mean_t' - `mean_c')/0.4304173

		svy: mean pc1_assets_new, over(tv2) coeflegend 

		mat M[2, 4] = _b[c.pc1_assets_new@1bn.tv2]
		mat M[2, 5] = _b[c.pc1_assets_new@0bn.tv2]
		lincom _b[c.pc1_assets_new@0bn.tv2] - _b[c.pc1_assets_new@1bn.tv2]
		loc mean_t = _b[c.pc1_assets_new@1bn.tv2]
		loc mean_c = _b[c.pc1_assets_new@0bn.tv2]
		return list
		mat M[2, 6] = r(p)
		svy: mean pc1_assets_new 
		estat sd
		matrix K[2,2] = (`mean_t' - `mean_c')/0.953125


		svy: mean sibtot, over(tv2) coeflegend 

		mat M[3, 4] = _b[c.sibtot@1bn.tv2]
		mat M[3, 5] = _b[c.sibtot@0bn.tv2]
		lincom _b[c.sibtot@0bn.tv2] - _b[c.sibtot@1bn.tv2]
		loc mean_t = _b[c.sibtot@1bn.tv2]
		loc mean_c = _b[c.sibtot@0bn.tv2]
		return list
		mat M[3, 6] = r(p)
		svy: mean sibtot 
		estat sd
		matrix K[3,2] = (`mean_t' - `mean_c')/2.795527



		svy: mean sisters, over(tv2) coeflegend 

		mat M[4, 4] = _b[c.sisters@1bn.tv2]
		mat M[4, 5] = _b[c.sisters@0bn.tv2]
		lincom _b[c.sisters@0bn.tv2] - _b[c.sisters@1bn.tv2]
		loc mean_t = _b[c.sisters@1bn.tv2]
		loc mean_c = _b[c.sisters@0bn.tv2]
		return list
		mat M[4, 6] = r(p)
		svy: mean sisters 
		estat sd
		matrix K[4,2] = (`mean_t' - `mean_c')/2.219933



		svy: mean oldersis, over(tv2) coeflegend 

		mat M[5, 4] = _b[c.oldersis@1bn.tv2]
		mat M[5, 5] = _b[c.oldersis@0bn.tv2]
		lincom _b[c.oldersis@0bn.tv2] - _b[c.oldersis@1bn.tv2]
		loc mean_t = _b[c.oldersis@1bn.tv2]
		loc mean_c = _b[c.oldersis@0bn.tv2]
		return list
		mat M[5, 6] = r(p)
		svy: mean oldersis 
		estat sd
		matrix K[5,2] = (`mean_t' - `mean_c')/ 1.851237



		svy: mean mother_alive, over(tv2) coeflegend 

		mat M[6, 4] = _b[c.mother_alive@1bn.tv2]
		mat M[6, 5] = _b[c.mother_alive@0bn.tv2]
		lincom _b[c.mother_alive@0bn.tv2] - _b[c.mother_alive@1bn.tv2]
		loc mean_t = _b[c.mother_alive@1bn.tv2]
		loc mean_c = _b[c.mother_alive@0bn.tv2]
		return list
		mat M[6, 6] = r(p)
		svy: mean mother_alive 
		estat sd
		matrix K[6,2] = (`mean_t' - `mean_c')/ 0.2358998



		svy: mean father_alive, over(tv2) coeflegend 

		mat M[7, 4] = _b[c.father_alive@1bn.tv2]
		mat M[7, 5] = _b[c.father_alive@0bn.tv2]
		lincom _b[c.father_alive@0bn.tv2] - _b[c.father_alive@1bn.tv2]
		loc mean_t = _b[c.father_alive@1bn.tv2]
		loc mean_c = _b[c.father_alive@0bn.tv2]
		return list
		mat M[7, 6] = r(p)
		svy: mean father_alive 
		estat sd
		matrix K[7,2] = (`mean_t' - `mean_c')/ 0.3018923


	rename _weight mah_weight
	rename _support mah_support

	*** Propensity score  matching

	psmatch2 tv2 urban  pc1_assets_new  sibtot  sisters oldersis mother_alive father_alive


	svyset [pw=_weight]


		svy: mean urban, over(tv2) coeflegend 

		mat M[1, 7] = _b[c.urban@1bn.tv2]
		mat M[1, 8] = _b[c.urban@0bn.tv2]
		lincom _b[c.urban@0bn.tv2] - _b[c.urban@1bn.tv2]
		loc mean_t = _b[c.urban@1bn.tv2]
		loc mean_c = _b[c.urban@0bn.tv2]
		return list
		mat M[1, 9] = r(p)
		svy: mean urban 
		estat sd
		matrix K[1,3] = (`mean_t' - `mean_c')/ 0.4278743


		svy: mean pc1_assets_new, over(tv2) coeflegend 

		mat M[2, 7] = _b[c.pc1_assets_new@1bn.tv2]
		mat M[2, 8] = _b[c.pc1_assets_new@0bn.tv2]
		lincom _b[c.pc1_assets_new@0bn.tv2] - _b[c.pc1_assets_new@1bn.tv2]
		loc mean_t = _b[c.pc1_assets_new@1bn.tv2]
		loc mean_c = _b[c.pc1_assets_new@0bn.tv2]
		return list
		mat M[2, 9] = r(p)
		svy: mean pc1_assets_new 
		estat sd
		matrix K[2,3] = (`mean_t' - `mean_c')/ 0.9905688



		svy: mean sibtot, over(tv2) coeflegend 

		mat M[3, 7] = _b[c.sibtot@1bn.tv2]
		mat M[3, 8] = _b[c.sibtot@0bn.tv2]
		lincom _b[c.sibtot@0bn.tv2] - _b[c.sibtot@1bn.tv2]
		loc mean_t = _b[c.sibtot@1bn.tv2]
		loc mean_c = _b[c.sibtot@0bn.tv2]
		return list
		mat M[3, 9] = r(p)
		svy: mean sibtot 
		estat sd
		matrix K[3,3] = (`mean_t' - `mean_c')/  3.45809


		svy: mean sisters, over(tv2) coeflegend 

		mat M[4, 7] = _b[c.sisters@1bn.tv2]
		mat M[4, 8] = _b[c.sisters@0bn.tv2]
		lincom _b[c.sisters@0bn.tv2] - _b[c.sisters@1bn.tv2]
		loc mean_t = _b[c.sisters@1bn.tv2]
		loc mean_c = _b[c.sisters@0bn.tv2]
		return list
		mat M[4, 9] = r(p)
		svy: mean sisters 
		estat sd
		matrix K[4,3] = (`mean_t' - `mean_c')/ 2.569581


		svy: mean oldersis, over(tv2) coeflegend 

		mat M[5, 7] = _b[c.oldersis@1bn.tv2]
		mat M[5, 8] = _b[c.oldersis@0bn.tv2]
		lincom _b[c.oldersis@0bn.tv2] - _b[c.oldersis@1bn.tv2]
		loc mean_t = _b[c.oldersis@1bn.tv2]
		loc mean_c = _b[c.oldersis@0bn.tv2]
		return list
		mat M[5, 9] = r(p)
		svy: mean oldersis 
		estat sd
		matrix K[5,3] = (`mean_t' - `mean_c')/ 1.970836


		svy: mean mother_alive, over(tv2) coeflegend 

		mat M[6, 7] = _b[c.mother_alive@1bn.tv2]
		mat M[6, 8] = _b[c.mother_alive@0bn.tv2]
		lincom _b[c.mother_alive@0bn.tv2] - _b[c.mother_alive@1bn.tv2]
		loc mean_t = _b[c.mother_alive@1bn.tv2]
		loc mean_c = _b[c.mother_alive@0bn.tv2]
		return list
		mat M[6, 9] = r(p)
		svy: mean mother_alive 
		estat sd
		matrix K[6,3] = (`mean_t' - `mean_c')/ 0.1806959



		svy: mean father_alive, over(tv2) coeflegend 

		mat M[7, 7] = _b[c.father_alive@1bn.tv2]
		mat M[7, 8] = _b[c.father_alive@0bn.tv2]
		lincom _b[c.father_alive@0bn.tv2] - _b[c.father_alive@1bn.tv2]
		loc mean_t = _b[c.father_alive@1bn.tv2]
		loc mean_c = _b[c.father_alive@0bn.tv2]
		return list
		mat M[7, 9] = r(p)
		svy: mean father_alive 
		estat sd
		matrix K[7,3] = (`mean_t' - `mean_c')/ 0.2781523



	rename _weight ps_weight
	rename _support ps_support
	gen ps_keep = 1 if _pscore >= 0.148352 & _pscore <= 0.7592347

	*** 2- Nearest neighbors matching

	psmatch2 tv2 urban  pc1_assets_new  sibtot  sisters oldersis mother_alive father_alive, n(2)

	svyset [pw=_weight]


		svy: mean urban, over(tv2) coeflegend 

		mat M[1, 10] = _b[c.urban@1bn.tv2]
		mat M[1, 11] = _b[c.urban@0bn.tv2]
		lincom _b[c.urban@0bn.tv2] - _b[c.urban@1bn.tv2]
		loc mean_t = _b[c.urban@1bn.tv2]
		loc mean_c = _b[c.urban@0bn.tv2]
		return list
		mat M[1, 12] = r(p)
		svy: mean urban 
		estat sd
		matrix K[1,4] = (`mean_t' - `mean_c')/ 0.428957



		svy: mean pc1_assets_new, over(tv2) coeflegend 

		mat M[2, 10] = _b[c.pc1_assets_new@1bn.tv2]
		mat M[2, 11] = _b[c.pc1_assets_new@0bn.tv2]
		lincom _b[c.pc1_assets_new@0bn.tv2] - _b[c.pc1_assets_new@1bn.tv2]
		loc mean_t = _b[c.pc1_assets_new@1bn.tv2]
		loc mean_c = _b[c.pc1_assets_new@0bn.tv2]
		return list
		mat M[2, 12] = r(p)
		svy: mean pc1_assets_new 
		estat sd
		matrix K[2,4] = (`mean_t' - `mean_c')/ 0.9601636



		svy: mean sibtot, over(tv2) coeflegend 

		mat M[3, 10] = _b[c.sibtot@1bn.tv2]
		mat M[3, 11] = _b[c.sibtot@0bn.tv2]
		lincom _b[c.sibtot@0bn.tv2] - _b[c.sibtot@1bn.tv2]
		loc mean_t = _b[c.sibtot@1bn.tv2]
		loc mean_c = _b[c.sibtot@0bn.tv2]
		return list
		mat M[3, 12] = r(p)
		svy: mean sibtot 
		estat sd
		matrix K[3,4] = (`mean_t' - `mean_c')/ 3.33721


		svy: mean sisters, over(tv2) coeflegend 

		mat M[4, 10] = _b[c.sisters@1bn.tv2]
		mat M[4, 11] = _b[c.sisters@0bn.tv2]
		lincom _b[c.sisters@0bn.tv2] - _b[c.sisters@1bn.tv2]
		loc mean_t = _b[c.sisters@1bn.tv2]
		loc mean_c = _b[c.sisters@0bn.tv2]
		return list
		mat M[4, 12] = r(p)
		svy: mean sisters 
		estat sd
		matrix K[4,4] = (`mean_t' - `mean_c')/ 2.61528


		svy: mean oldersis, over(tv2) coeflegend 

		mat M[5, 10] = _b[c.oldersis@1bn.tv2]
		mat M[5, 11] = _b[c.oldersis@0bn.tv2]
		lincom _b[c.oldersis@0bn.tv2] - _b[c.oldersis@1bn.tv2]
		loc mean_t = _b[c.oldersis@1bn.tv2]
		loc mean_c = _b[c.oldersis@0bn.tv2]
		return list
		mat M[5, 12] = r(p)
		svy: mean oldersis 
		estat sd
		matrix K[5,4] = (`mean_t' - `mean_c')/ 1.934119



		svy: mean mother_alive, over(tv2) coeflegend 

		mat M[6, 10] = _b[c.mother_alive@1bn.tv2]
		mat M[6, 11] = _b[c.mother_alive@0bn.tv2]
		lincom _b[c.mother_alive@0bn.tv2] - _b[c.mother_alive@1bn.tv2]
		loc mean_t = _b[c.mother_alive@1bn.tv2]
		loc mean_c = _b[c.mother_alive@0bn.tv2]
		return list
		mat M[6, 12] = r(p)
		svy: mean mother_alive 
		estat sd
		matrix K[6,4] = (`mean_t' - `mean_c')/ 0.1911526


		svy: mean father_alive, over(tv2) coeflegend 

		mat M[7, 10] = _b[c.father_alive@1bn.tv2]
		mat M[7, 11] = _b[c.father_alive@0bn.tv2]
		lincom _b[c.father_alive@0bn.tv2] - _b[c.father_alive@1bn.tv2]
		loc mean_t = _b[c.father_alive@1bn.tv2]
		loc mean_c = _b[c.father_alive@0bn.tv2]
		return list
		mat M[7, 12] = r(p)
		svy: mean father_alive 
		estat sd
		matrix K[7,4] = (`mean_t' - `mean_c')/ 0.3278033


	rename _weight nn2_weight
	rename _support nn2_support
	gen nn2_keep = 1 if _pscore >= 0.1432861  & _pscore <= 0.7592347


	*** Entropy balancing on mean


	ebalance tv2 urban  pc1_assets_new  sibtot  sisters oldersis mother_alive father_alive, targets(1)  g(_eb1)


	svyset [pw=_eb1]


		svy: mean urban, over(tv2) coeflegend 

		mat M[1, 13] = _b[c.urban@1bn.tv2]
		mat M[1, 14] = _b[c.urban@0bn.tv2]
		lincom _b[c.urban@0bn.tv2] - _b[c.urban@1bn.tv2]
		loc mean_t = _b[c.urban@1bn.tv2]
		loc mean_c = _b[c.urban@0bn.tv2]
		return list
		mat M[1, 15] = r(p)
		svy: mean urban 
		estat sd
		matrix K[1,5] = (`mean_t' - `mean_c')/ 0.4303823



		svy: mean pc1_assets_new, over(tv2) coeflegend 

		mat M[2, 13] = _b[c.pc1_assets_new@1bn.tv2]
		mat M[2, 14] = _b[c.pc1_assets_new@0bn.tv2]
		lincom _b[c.pc1_assets_new@0bn.tv2] - _b[c.pc1_assets_new@1bn.tv2]
		loc mean_t = _b[c.pc1_assets_new@1bn.tv2]
		loc mean_c = _b[c.pc1_assets_new@0bn.tv2]
		return list
		mat M[2, 15] = r(p)
		svy: mean pc1_assets_new 
		estat sd
		matrix K[2,5] = (`mean_t' - `mean_c')/ 0.9442445


		svy: mean sibtot, over(tv2) coeflegend 

		mat M[3, 13] = _b[c.sibtot@1bn.tv2]
		mat M[3, 14] = _b[c.sibtot@0bn.tv2]
		lincom _b[c.sibtot@0bn.tv2] - _b[c.sibtot@1bn.tv2]
		loc mean_t = _b[c.sibtot@1bn.tv2]
		loc mean_c = _b[c.sibtot@0bn.tv2]
		return list
		mat M[3, 15] = r(p)
		svy: mean sibtot 
		estat sd
		matrix K[3,5] = (`mean_t' - `mean_c')/  3.267997


		svy: mean sisters, over(tv2) coeflegend 

		mat M[4, 13] = _b[c.sisters@1bn.tv2]
		mat M[4, 14] = _b[c.sisters@0bn.tv2]
		lincom _b[c.sisters@0bn.tv2] - _b[c.sisters@1bn.tv2]
		loc mean_t = _b[c.sisters@1bn.tv2]
		loc mean_c = _b[c.sisters@0bn.tv2]
		return list
		mat M[4, 15] = r(p)
		svy: mean sisters 
		estat sd
		matrix K[4,5] = (`mean_t' - `mean_c')/  2.448237



		svy: mean oldersis, over(tv2) coeflegend 

		mat M[5, 13] = _b[c.oldersis@1bn.tv2]
		mat M[5, 14] = _b[c.oldersis@0bn.tv2]
		lincom _b[c.oldersis@0bn.tv2] - _b[c.oldersis@1bn.tv2]
		loc mean_t = _b[c.oldersis@1bn.tv2]
		loc mean_c = _b[c.oldersis@0bn.tv2]
		return list
		mat M[5, 15] = r(p)
		svy: mean oldersis 
		estat sd
		matrix K[5,5] = (`mean_t' - `mean_c')/  1.939011




		svy: mean mother_alive, over(tv2) coeflegend 

		mat M[6, 13] = _b[c.mother_alive@1bn.tv2]
		mat M[6, 14] = _b[c.mother_alive@0bn.tv2]
		lincom _b[c.mother_alive@0bn.tv2] - _b[c.mother_alive@1bn.tv2]
		loc mean_t = _b[c.mother_alive@1bn.tv2]
		loc mean_c = _b[c.mother_alive@0bn.tv2]
		return list
		mat M[6, 15] = r(p)
		svy: mean mother_alive 
		estat sd
		matrix K[6,5] = (`mean_t' - `mean_c')/  0.2356158



		svy: mean father_alive, over(tv2) coeflegend 

		mat M[7, 13] = _b[c.father_alive@1bn.tv2]
		mat M[7, 14] = _b[c.father_alive@0bn.tv2]
		lincom _b[c.father_alive@0bn.tv2] - _b[c.father_alive@1bn.tv2]
		loc mean_t = _b[c.father_alive@1bn.tv2]
		loc mean_c = _b[c.father_alive@0bn.tv2]
		return list
		mat M[7, 15] = r(p)
		svy: mean father_alive 
		estat sd
		matrix K[7,5] = (`mean_t' - `mean_c')/  0.3016354


	**** EB on 1st moments and 1st order interactions

	set more off
	foreach v in urban pc1_assets_new sibtot sisters oldersis mother_alive father_alive   {
	foreach m in urban pc1_assets_new sibtot sisters oldersis mother_alive father_alive  {
	gen `v'X`m'=`v'*`m'
	}
	}


	ebalance tv2 urban pc1_assets_new sibtot sisters oldersis mother_alive father_alive   ///
	urbanXpc1_assets_new urbanXsibtot urbanXsisters urbanXoldersis  ///
	pc1_assets_newXpc1_assets_new pc1_assets_newXsibtot pc1_assets_newXsisters pc1_assets_newXoldersis pc1_assets_newXmother_alive pc1_assets_newXfather_alive   ///
	sibtotXsibtot sibtotXsisters sibtotXoldersis  ///
	sistersXsisters sistersXoldersis   ///
	oldersisXoldersis , g(_webal1int)

	svyset [pw=_webal1int]


		svy: mean urban, over(tv2) coeflegend 

		mat M[1, 16] = _b[c.urban@1bn.tv2]
		mat M[1, 17] = _b[c.urban@0bn.tv2]
		lincom _b[c.urban@0bn.tv2] - _b[c.urban@1bn.tv2]
		loc mean_t = _b[c.urban@1bn.tv2]
		loc mean_c = _b[c.urban@0bn.tv2]
		return list
		mat M[1, 18] = r(p)
		svy: mean urban 
		estat sd
		matrix K[1,6] = (`mean_t' - `mean_c')/ 0.4300663



		svy: mean pc1_assets_new, over(tv2) coeflegend 

		mat M[2, 16] = _b[c.pc1_assets_new@1bn.tv2]
		mat M[2, 17] = _b[c.pc1_assets_new@0bn.tv2]
		lincom _b[c.pc1_assets_new@0bn.tv2] - _b[c.pc1_assets_new@1bn.tv2]
		loc mean_t = _b[c.pc1_assets_new@1bn.tv2]
		loc mean_c = _b[c.pc1_assets_new@0bn.tv2]
		return list
		mat M[2, 18] = r(p)
		svy: mean pc1_assets_new 
		estat sd
		matrix K[2,6] = (`mean_t' - `mean_c')/ 1.004503


		svy: mean sibtot, over(tv2) coeflegend 

		mat M[3, 16] = _b[c.sibtot@1bn.tv2]
		mat M[3, 17] = _b[c.sibtot@0bn.tv2]
		lincom _b[c.sibtot@0bn.tv2] - _b[c.sibtot@1bn.tv2]
		loc mean_t = _b[c.sibtot@1bn.tv2]
		loc mean_c = _b[c.sibtot@0bn.tv2]
		return list
		mat M[3, 18] = r(p)
		svy: mean sibtot 
		estat sd
		matrix K[3,6] = (`mean_t' - `mean_c')/ 2.925762


		svy: mean sisters, over(tv2) coeflegend 

		mat M[4, 16] = _b[c.sisters@1bn.tv2]
		mat M[4, 17] = _b[c.sisters@0bn.tv2]
		lincom _b[c.sisters@0bn.tv2] - _b[c.sisters@1bn.tv2]
		loc mean_t = _b[c.sisters@1bn.tv2]
		loc mean_c = _b[c.sisters@0bn.tv2]
		return list
		mat M[4, 18] = r(p)
		svy: mean sisters 
		estat sd
		matrix K[4,6] = (`mean_t' - `mean_c')/ 2.41118



		svy: mean oldersis, over(tv2) coeflegend 

		mat M[5, 16] = _b[c.oldersis@1bn.tv2]
		mat M[5, 17] = _b[c.oldersis@0bn.tv2]
		lincom _b[c.oldersis@0bn.tv2] - _b[c.oldersis@1bn.tv2]
		loc mean_t = _b[c.oldersis@1bn.tv2]
		loc mean_c = _b[c.oldersis@0bn.tv2]
		return list
		mat M[5, 18] = r(p)
		svy: mean oldersis 
		estat sd
		matrix K[5,6] = (`mean_t' - `mean_c')/  2.040395




		svy: mean mother_alive, over(tv2) coeflegend 

		mat M[6, 16] = _b[c.mother_alive@1bn.tv2]
		mat M[6, 17] = _b[c.mother_alive@0bn.tv2]
		lincom _b[c.mother_alive@0bn.tv2] - _b[c.mother_alive@1bn.tv2]
		loc mean_t = _b[c.mother_alive@1bn.tv2]
		loc mean_c = _b[c.mother_alive@0bn.tv2]
		return list
		mat M[6, 18] = r(p)
		svy: mean mother_alive 
		estat sd
		matrix K[6,6] = (`mean_t' - `mean_c')/ 0.2359242



		svy: mean father_alive, over(tv2) coeflegend 

		mat M[7, 16] = _b[c.father_alive@1bn.tv2]
		mat M[7, 17] = _b[c.father_alive@0bn.tv2]
		lincom _b[c.father_alive@0bn.tv2] - _b[c.father_alive@1bn.tv2]
		loc mean_t = _b[c.father_alive@1bn.tv2]
		loc mean_c = _b[c.father_alive@0bn.tv2]
		return list
		mat M[7, 18] = r(p)
		svy: mean father_alive 
		estat sd
		matrix K[7,6] = (`mean_t' - `mean_c')/ 0.3017473






	matrix list K
	estout matrix(K, fmt(4)) using "output/intermediate/differentmatching_standardizeddif.tex", replace  prehead(`"{"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' `"\begin{tabular}{l*{4}{c}}"' `"\hline\hline"')  posthead("\hline") prefoot("\hline") postfoot(`"\hline\hline"' `"\end{tabular}"' `"}"')


	svmat K
	 
import excel "output/intermediate/Standardized differences.xlsx", sheet("Transposed") firstrow clear

	destring Urban Assets Totalsiblings Sisters Olderssisters Motheralive Fatheralive,replace

	gen id = _n 

	graph dot (asis) Urban  Assets Totalsiblings Sisters Olderssisters Motheralive Fatheralive, over(A, relabel(2 "EB (1st moments)" 3 "EB (1st moments+1st order interactions)") sort(id)  label(angle(default) labsize(small))) legend(rows(2)) yline(0, lpattern(dash) lcolor(dknavy%40)) title(Standardized differences) 

	graph export "output/graphs/FigureA3.pdf", replace 



*** ----------------------------------------------------------------------
**## 						Table A1
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear


	
	global C "birth_y urban pc1_assets_new pc1_assets_new_sq"

	eststo col1: reg tv2 sibtot $C i.dhsregion if sisters!=. & analysis1==1 , ro  
	eststo col2: reg tv2 sibtot sisters $C i.dhsregion if sisters!=. & analysis1==1 , ro  
	eststo col3: reg tv2 sibtot sisters oldersis $C i.dhsregion if sisters!=. & analysis1==1  , ro  
	eststo col4: reg tv2 sibtot sisters oldersis livedwithmoth livedwithfath bothbirthparents $C i.dhsregion if sisters!=. & analysis1==1  , ro  
 
	eststo col5: reg tv2 diffidealgirls1998 $C i.dhsregion if sisters!=. & analysis1==1 , ro 
	eststo col6: reg tv2 order1998 $C i.dhsregion if sisters!=. & analysis1==1 , ro 
	
	eststo col5_2: reg tv2 sibtot sisters oldersis diffidealgirls1998 $C i.dhsregion if sisters!=. & analysis1==1 , ro 
	eststo col6_2: reg tv2 sibtot sisters oldersis order1998 $C i.dhsregion if sisters!=. & analysis1==1 , ro 

	eststo col7: reg tv2 sibtot $C i.dhsregion if sisters!=. & analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt], ro  
	eststo col8: reg tv2 sibtot sisters $C i.dhsregion if sisters!=. & analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt], ro  
	eststo col9: reg tv2 sibtot sisters oldersis $C i.dhsregion if sisters!=. & analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt], ro  
	eststo col10: reg tv2 sibtot sisters oldersis livedwithmoth livedwithfath bothbirthparents $C i.dhsregion if sisters!=. & analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt], ro   

	eststo col11: reg tv2 diffidealgirls1998 $C i.dhsregion if sisters!=. & analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt] , ro 
	eststo col12: reg tv2 order1998 $C i.dhsregion if sisters!=. &  analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt], ro 

	eststo col11_2: reg tv2 sibtot sisters oldersis diffidealgirls1998 $C i.dhsregion if sisters!=. & analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt] , ro 
	eststo col12_2: reg tv2 sibtot sisters oldersis order1998 $C i.dhsregion if sisters!=. &  analysis2_2008==1 & weight_prov_2y!=. [pweight=wgt], ro 

	
	esttab col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 col11 col12 ///
	using "output/tables/TableA1.tex", ///
	title(Household composition - multivariate analysis)  ///
	order(sibtot sisters oldersis livedwithmoth livedwithfath bothbirthparents diffidealgirls1998 order1998) ///
	keep(sibtot sisters oldersis livedwithmoth livedwithfath bothbirthparents diffidealgirls1998 order1998) ///
	label cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) noconstant ///
	stats(r2  N, fmt(%9.3f %9.0g) labels(R$^2$ Observations)) eqlabels(none) style(tex) replace
	estimates drop _all	
	

		


*** ----------------------------------------------------------------------
**## 						Table A2
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear

		reg tv2 spei12_pos spei12_neg i.q102b , ro
		distinct q102a if e(sample)==1
		levelsof q102a if e(sample)==1, local(villages) 



use "$traffick_repl_local/input/rainfall_replication.dta", clear

encode q102a, gen(q102a_d)

			* Only keep villages and years that are in the regression sample (filling in the gaps in years)
			gen villageOK = 0
				foreach n of local villages {
				replace villageOK = 1 if (q102a =="`n'")
				}
			keep if villageOK==1
			keep if rain_y>1977 & rain_y<2010
		
			* Variance decomposition 
			xtset q102a_d rain_y
			xtsum spei12  
				local meanoverall = r(mean)
				local meanoverall: di %8.3f `meanoverall' 
				local sd_overall = r(sd)
				local sd_overall: di %8.3f `sd_overall'
				local sd_between = r(sd_b)
				local sd_between: di %8.3f `sd_between'
				local N = r(N)
				local T = r(Tbar)
				local n = r(n) 
		
				* Quantification of variance decomposition
				* We test Maria Elena Bontempi's procedure: xtsum3 (saved in \ado\personal folder) 
				xtset q102a_d rain_y
				xtsum3 spei12, ur
			
				local sd_within = r(WSDfe2_spei12) 
				local sd_within: di %8.3f `sd_within'

				local between_pc = r(BSSpr2_spei12)   
				local between_pc : di %8.2f `between_pc'
				di `between_pc'
				local within_pc =  r(WSSpfe2_spei12)   
				local within_pc : di %8.2f `within_pc'
				di `within_pc'
				
				local res = r(RSDfet21_spei12)
				local res : di %8.3f `res'
				di `res'
				
				local common_factor = r(BSDr1_spei12) 
				local common_factor : di %8.3f `common_factor'
				di `common_factor'			
				
				local res_ss = r(RSSpfet21_spei12)
				local res_ss: di %8.2f `res_ss'
				di `res_ss'
				
				local common_ss = r(BSSpr1_spei12)
				local common_ss: di %8.2f `common_ss'
				di `common_ss'
				
				local pc_2 = r(BSSppr1_spei12)
				local pc_2: di %8.2f `pc_2'
				di `pc_2'						
			
				cap file close soutput
				file open soutput using "output/tables/TableA2.tex", write replace
				file write soutput "\begin{table}[htbp] \centering \caption{Variance decomposition of the weather index - full reference period (1978-2009)} \begin{threeparttable} \begin{tabular}{l|cccccccc}  \hline\hline "  _n
				file write soutput "Variation & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Std. deviation} & \multicolumn{1}{c}{\% SS}  && \multicolumn{2}{c}{Observations} \\" _n
				file write soutput "\\[-1.8ex]\hline\\[-1.8ex]" _n
	
				file write soutput "Overall & `meanoverall'  & `sd_overall' & && N = & `N' \\" _n
				file write soutput "1. Between & & `sd_between'  & `between_pc' && n = & `n' \\" _n
				file write soutput "2. Within & & `sd_within'  & `within_pc' && T = & `T' \\" _n
				file write soutput "\hspace{3mm} of which & &  \\" _n
				file write soutput "\hspace{6mm} 2a. Residual & & `res' & `res_ss' & \\" _n
				file write soutput "\hspace{6mm} 2b. Due to common factor & & `common_factor'& `common_ss' & \\" _n
				file write soutput "\hspace{6mm} (2b. in \% of 2) & &  & (`pc_2')		 & \\" _n

				file write soutput "\\[-1.8ex]\hline\hline" _n
				file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:}  Variance decomposition of SPEI is computed using all villages in the final shelter sample (n = 97), and the 1978-2009 time span (T = 32).  \end{tablenotes} \end{threeparttable} \end{table}"
				file close soutput	
			

*** ----------------------------------------------------------------------
**## 						Table A3
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear

		global C "urban pc1_assets_new pc1_assets_new_sq sibtot sisters oldersis mother_alive father_alive alivemissing"

		keep if shelter == 1
		reg tv2 spei12_pos spei12_neg i.q102b
		keep if e(sample) == 1
				encode q102a, gen(q102a_d)
				
		* On regression sample (unbalanced panel: only some years for some villages)
		
		keep q102a_d rain_y spei12 
		duplicates drop 
		drop if spei12==. | rain_y==. | q102a_d==.

		xtset q102a_d rain_y
		xtsum3 spei12 
		
		local meanoverall = r(TM_spei12) 
		local meanoverall: di %8.3f `meanoverall'
		
		local sd_overall = r(TSD_spei12) 
		local sd_overall: di %8.3f `sd_overall'
		
		local sd_between = r(BSDr1_spei12) 
		local sd_between: di %8.3f `sd_between'

		local sd_within = r(WSDfe2_spei12) 
		local sd_within: di %8.3f `sd_within'

		local between_pc = r(BSSpr2_spei12)   
		local between_pc : di %8.2f `between_pc'
		
		local within_pc =  r(WSSpfe2_spei12)   
		local within_pc : di %8.2f `within_pc'
	
		local res = r(RSDfet21_spei12)
		local res : di %8.3f `res'
		di `res'
		
		local common_factor = r(BSDr1_spei12) 
		local common_factor : di %8.3f `common_factor'
		di `common_factor'			
		
		local res_ss = r(RSSpfet21_spei12)
		local res_ss: di %8.2f `res_ss'
		di `res_ss'
		
		local common_ss = r(BSSpr1_spei12)
		local common_ss: di %8.2f `common_ss'
		di `common_ss'
		
		local pc_2 = r(BSSppr1_spei12)
		local pc_2: di %8.2f `pc_2'
		di `pc_2'		
		
			cap file close soutput
			file open soutput using  "output/tables/TableA3.tex", write replace
			file write soutput "\begin{table}[htbp] \centering \caption{Variance decomposition of the weather index - restricted to year before girls left villages} \begin{threeparttable} \begin{tabular}{l|cccccccc}  \hline\hline "  _n
			file write soutput "Variation & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Std. deviation} & \multicolumn{1}{c}{\% SS}  && \multicolumn{2}{c}{Observations} \\" _n
			file write soutput "\\[-1.8ex]\hline\\[-1.8ex]" _n
			file write soutput "Overall & `meanoverall'  & `sd_overall' & && N = & 213 \\" _n
			file write soutput "1. Between & & 0.649  & `between_pc' && n = & 97 \\" _n
			file write soutput "2. Within & & `sd_within'  & `within_pc' && T-bar = & 2.19 \\" _n
			file write soutput "\hspace{3mm} of which & &  \\" _n
			file write soutput "\hspace{6mm} 2a. Residual & & `res'& `res_ss' & \\" _n
			file write soutput "\hspace{6mm} 2b. Due to common factor & & `common_factor' & `common_ss' & \\" _n
			file write soutput "\hspace{6mm} (2b. in \% of 2) & &  & (`pc_2') & \\" _n
			file write soutput "\\[-1.8ex]\hline\hline" _n
			file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} Variance decomposition of SPEI is computed using the final shelter sample (for each of the 97 villages) and only including the years before the girls left the villages.. The quantification (\% SS) is obtained using the xtsum3 procedure created by Maria Elena Bontempi (University of Bologna). \end{tablenotes} \end{threeparttable} \end{table}"
			file close soutput	
			
			

*** ----------------------------------------------------------------------
**## 						Table A4
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear
	
	global C "urban pc1_assets_new pc1_assets_new_sq sibtot sisters oldersis mother_alive father_alive alivemissing i.q102b"

	local ll = 1
	foreach var in girl_leaving firstleaver marriedfor_hh backtosch_hh sendmoney_hh {
		xi: reg `var' tv2 $C, ro 
		local beta_c1_r = _b[tv2]
		local sigma_c1_r = _se[tv2]
		local beta_c1_r`ll' : di %8.3f `beta_c1_r'
		local sigma_c1_r`ll' : di %8.3f `sigma_c1_r'
		matrix rtable = r(table)
		local pvalue  = rtable[4,1] 
		local star_c1_r`ll' = ""
			if `pvalue' < 0.1 local star_c1_r`ll'= "*" 
			if `pvalue' < 0.05 local star_c1_r`ll' = "**" 
			if `pvalue' < 0.01 local star_c1_r`ll' = "***" 
		local N_c1_r`ll' = e(N)
		su `var' if e(sample)==1 & tv2==0
		local mcontrol_c1_r = r(mean)
		local mcontrol_c1_r`ll' : di %8.3f `mcontrol_c1_r'
			
		local ll = `ll'+1
	}

		cap file close soutput
		file open soutput using  "output/tables/TableA4.tex", write replace
		file write soutput "\begin{table}[htbp] \centering  \caption{Expectations prior to leaving the household - with controls} \begin{threeparttable} \begin{tabular}{lccc} \\[-1.8ex] \hline\hline \\[-1.8ex]"  _n
		file write soutput "& (1) & (2) & (3)  \\   " _n
		file write soutput "  \textit{Dependent variables:}  & Trafficked (OLS)  & Not trafficked (mean) & Observations \\ "_n
		file write soutput "\\[-1.8ex]\hline\\[-1.8ex]" _n
	
		file write soutput "Personally knew a girl who left village & `beta_c1_r1'`star_c1_r1' & `mcontrol_c1_r1' & `N_c1_r1' \\" _n
		file write soutput "& (`sigma_c1_r1') &\\ " _n
		file write soutput "First to leave household & `beta_c1_r2'`star_c1_r2' & `mcontrol_c1_r2' & `N_c1_r2' \\" _n
		file write soutput "& (`sigma_c1_r2') &\\ " _n
		file write soutput "Likelihood of marrying a foreign man (\%) & `beta_c1_r3'`star_c1_r3' & `mcontrol_c1_r3' & `N_c1_r3' \\" _n
		file write soutput "& (`sigma_c1_r3') &\\ " _n
		file write soutput "Likelihood of going back to school (\%) & `beta_c1_r4'`star_c1_r4' & `mcontrol_c1_r4' & `N_c1_r4' \\" _n
		file write soutput "& (`sigma_c1_r4') &\\ " _n
		file write soutput "Likelihood of sending money home (\%) & `beta_c1_r5'`star_c1_r5' & `mcontrol_c1_r5' & `N_c1_r5' \\" _n
		file write soutput "& (`sigma_c1_r5') &\\ " _n

		file write soutput "\\[-1.8ex]\hline\hline\\[-1.8ex]" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} Column 1 reports the results of an OLS regression of each dependent variable on the trafficked status, with observations in Column 3: each coefficient is the result of a different regression. Column 2 reports the mean of each dependent variable in the non-trafficked sub-group. The estimations include controls for a respondent's number of siblings, sisters, and older sisters, as well as region fixed effects, whether her household was urban, whether her mother was alive, whether her father was alive, and the household's assets and assets squared. Assets are measured through an index that captures ownership of durable goods (bicycle, car, motorcycle, radio, refrigerator, television). Robust standard errors are in parentheses. *, ** and *** indicate significance at the 10, 5, 1\% levels." _n
		file write soutput "\end{tablenotes} \end{threeparttable} \end{table}"
		file close soutput	

		

*** ----------------------------------------------------------------------
**## 						Table A5
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear
			

	global C "urban pc1_assets_new pc1_assets_new_sq sibtot sisters oldersis mother_alive father_alive alivemissing i.q102b"

	local ll = 1
	foreach var in hn_q504_amount_required discount  hn_q505_sure_amount riskcoef risk impulse  confident conform contactfamily wantchild tn_expectwage {
		xi: reg `var' tv2 $C, ro 
		local beta_c1_r = _b[tv2]
		local sigma_c1_r = _se[tv2]
		local beta_c1_r`ll' : di %8.3f `beta_c1_r'
		local sigma_c1_r`ll' : di %8.3f `sigma_c1_r'
		matrix rtable = r(table)
		local pvalue  = rtable[4,1] 
		local star_c1_r`ll' = ""
			if `pvalue' < 0.1 local star_c1_r`ll'= "*" 
			if `pvalue' < 0.05 local star_c1_r`ll' = "**" 
			if `pvalue' < 0.01 local star_c1_r`ll' = "***" 
		local N_c1_r`ll' = e(N)
		su `var' if e(sample)==1 & tv2==0
		local mcontrol_c1_r = r(mean)
		local mcontrol_c1_r`ll' : di %8.3f `mcontrol_c1_r'
			
		local ll = `ll'+1
	}

		cap file close soutput
		file open soutput using "output/tables/TableA5.tex", write replace
		file write soutput "\begin{table}[htbp] \centering  \caption{Preferences and expectations by trafficked status - with controls} \begin{threeparttable} \begin{tabular}{lccc} \\[-1.8ex] \hline\hline \\[-1.8ex]"  _n
		file write soutput "& (1) & (2) & (3)  \\   " _n
		file write soutput "  \textit{Dependent variables:}  & Trafficked (OLS)  & Not trafficked (mean) & Observations \\ "_n
		file write soutput "\\[-1.8ex]\hline\\[-1.8ex]" _n
	
		file write soutput "Amount in 5wks (hundreds PHP)$^a$ & `beta_c1_r1'`star_c1_r1' & `mcontrol_c1_r1' & `N_c1_r1' \\" _n
		file write soutput "& (`sigma_c1_r1') &\\ " _n
		file write soutput "Discount rate & `beta_c1_r2'`star_c1_r2' & `mcontrol_c1_r2' & `N_c1_r2' \\" _n
		file write soutput "& (`sigma_c1_r2') &\\ " _n
		file write soutput "Sure amount (hundreds PHP)$^b$ & `beta_c1_r3'`star_c1_r3' & `mcontrol_c1_r3' & `N_c1_r3' \\" _n
		file write soutput "& (`sigma_c1_r3') &\\ " _n
		file write soutput "Risk coefficient & `beta_c1_r4'`star_c1_r4' & `mcontrol_c1_r4' & `N_c1_r4' \\" _n
		file write soutput "& (`sigma_c1_r4') &\\ " _n
		file write soutput "Willingness to take risks (self-reported) & `beta_c1_r5'`star_c1_r5' & `mcontrol_c1_r5' & `N_c1_r5' \\" _n
		file write soutput "& (`sigma_c1_r5') &\\ " _n
		file write soutput "Impulsiveness (self-reported) & `beta_c1_r6'`star_c1_r6' & `mcontrol_c1_r6' & `N_c1_r6' \\" _n
		file write soutput "& (`sigma_c1_r6') &\\ " _n
		file write soutput "Confidence (self-reported) & `beta_c1_r7'`star_c1_r7' & `mcontrol_c1_r7' & `N_c1_r7' \\" _n
		file write soutput "& (`sigma_c1_r7') &\\ " _n
		file write soutput "Importance of conforming to expectations (self-reported) & `beta_c1_r8'`star_c1_r8' & `mcontrol_c1_r8' & `N_c1_r8' \\" _n
		file write soutput "& (`sigma_c1_r8') &\\ " _n
		file write soutput "Has contact with family & `beta_c1_r9'`star_c1_r9' & `mcontrol_c1_r9' & `N_c1_r9' \\" _n
		file write soutput "& (`sigma_c1_r9') &\\ " _n
		file write soutput "Wants children & `beta_c1_r10'`star_c1_r10' & `mcontrol_c1_r10' & `N_c1_r10' \\" _n
		file write soutput "& (`sigma_c1_r10') &\\ " _n
		file write soutput "Expected wage in next job (thousands PHP) & `beta_c1_r11'`star_c1_r11' & `mcontrol_c1_r11' & `N_c1_r11' \\" _n
		file write soutput "& (`sigma_c1_r11') &\\ " _n

		file write soutput "\\[-1.8ex]\hline\hline\\[-1.8ex]" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} CColumn 1 reports the results of an OLS regression of each dependent variable on trafficked, with observations in Column 3. Column 2 reports the mean of each dependent variable in the non- trafficked sub-group. The estimations include controls for a respondent's number of siblings, sisters, and older sisters, as well as region fixed effects, whether her household was urban, whether her mother was alive, whether her father was alive, and the household's assets and assets squared. Assets are measured through an index that captures ownership of durable goods (bicycle, car, motorcycle, radio, refrigerator, television). Robust standard errors are in parentheses. *, ** and *** indicate significance at the 10, 5, 1\% levels.\\ $^{a}$ Amount in 5wks (PHP) is the respondent's preferred sum to receive in five weeks' time instead of 500PHP in one week's time.\\ $^{b}$ Sure amount (PHP) is the sum a respondent would like to receive with certainty instead of choosing to participate in a lottery game that yields 0PHP with a probability of 50\% and 500PHP with a probability of 50\%. "_n
		file write soutput "\end{tablenotes} \end{threeparttable} \end{table}"
		file close soutput	


*** ----------------------------------------------------------------------
**## 						Table A6
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear



	global C "edu aboveprimary abovesecondary urban pc1_assets_new electricity"
	
	* Unmatched for shelter, matches (but no weights) for DHS 

		* Trafficked (mean & sd)
		local ll = 1
		foreach var in $C {
			summarize `var' if tv2==1 
			local mean_traff_`ll' = r(mean) 
			local sd_traff_`ll' = r(sd) 
			local N_traff_`ll' = r(N)  
			local mean_traff_`ll' : di %8.2f `mean_traff_`ll''
			local sd_traff_`ll' : di %8.2f `sd_traff_`ll''			
			local ll = `ll'+1
			}
			di `mean_traff_1'
			
		* Not trafficked in shelters (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if  tv2==0 & shelter==1  
			local mean_sh_`ll' = r(mean) 
			local sd_sh_`ll' = r(sd) 
			local N_sh_`ll' = r(N)  
			local mean_sh_`ll' : di %8.2f `mean_sh_`ll''
			local sd_sh_`ll' : di %8.2f `sd_sh_`ll''			
			local ll = `ll'+1
			}
			
		* Trafficked vs not trafficked in shelters (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' tv2 if analysis1==1  
			local N_regsh_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue_sh_`ll'  = rtable[4,1] 
			local pvalue_sh_`ll' : di %8.3f `pvalue_sh_`ll''
			local ll = `ll'+1
			}
		
	foreach weight in weight_reg_exact  {
	
		* Not trafficked in DHS (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if tv2==0 & analysis2_2008==1 & `weight'!=. [aweight=wgt] 
			local mean_`weight'_`ll' = r(mean) 
			local sd_`weight'_`ll' = r(sd) 
			local N_`weight'_`ll' = r(N)  
			local mean_`weight'_`ll' : di %8.2f `mean_`weight'_`ll''
			local sd_`weight'_`ll' : di %8.2f `sd_`weight'_`ll''			
			local ll = `ll'+1
			}
			
		* Trafficked vs not trafficked in DHS (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' tv2 if tv2==1 | (analysis2_2008==1 & `weight'!=.) [pweight=wgt]
			local N_reg1_`weight'_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue_`weight'_`ll' = rtable[4,1] 
			local pvalue_`weight'_`ll' : di %8.3f `pvalue_`weight'_`ll''
			local ll = `ll'+1
			}
			
		* Not trafficked in shelters vs not trafficked in DHS (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' analysis1 if (tv2==0 & shelter==1) | (tv2==0 & analysis2_2008==1 & `weight'!=.) [pweight=wgt] 
			local N_reg2_`weight'_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue2_`weight'_`ll' = rtable[4,1] 
			local pvalue2_`weight'_`ll' : di %8.3f `pvalue2_`weight'_`ll''
			local ll = `ll'+1
			}
	
		* Table
		
		cap file close soutput
		file open soutput using "output/tables/TableA6.tex", write replace
		file write soutput "\begin{sidewaystable}[htbp] \centering \footnotesize \caption{Socioeconomic background - exact matches at the region level} \begin{threeparttable}\begin{tabular}{l | c c c | c c c | c c c | c | c | c} \hline\hline"  _n
		file write soutput " &\multicolumn{3}{c|}{Trafficked} &\multicolumn{3}{c|}{\makecell{Not trafficked \\ in shelters}} &\multicolumn{3}{c|}{DHS sample} &\multicolumn{1}{c|}{\makecell{Trafficked vs. not \\ trafficked in shelters}} &\multicolumn{1}{c|}{\makecell{Trafficked vs. \\ DHS sample}} &\multicolumn{1}{c}{\makecell{Not trafficked in shelters \\ vs. DHS sample}}  \\" _n
		file write soutput "& \multicolumn{3}{c|}{(1)}  & \multicolumn{3}{c|}{(2)} & \multicolumn{3}{c|}{(3)} & \multicolumn{1}{c|}{(4)} & \multicolumn{1}{c|}{(5)}  &  \multicolumn{1}{c}{(6)} \\" _n
		file write soutput "  & \textit{Mean} & \textit{SD}  & \textit{Obs.} & \textit{Mean} & \textit{SD} & \textit{Obs.} & \textit{Mean} & \textit{SD} & \textit{Obs.} & \textit{p-value} & \textit{p-value} & \textit{p-value}\\ "_n
		file write soutput "\hline" _n
	
		file write soutput "Years of education & `mean_traff_1' & `sd_traff_1' & `N_traff_1' & `mean_sh_1' & `sd_sh_1' & `N_sh_1' & `mean_`weight'_1' & `sd_`weight'_1' & `N_`weight'_1' & `pvalue_sh_1' & `pvalue_`weight'_1' &  `pvalue2_`weight'_1' \\" _n
		file write soutput "Above primary education & `mean_traff_2' & `sd_traff_2' & `N_traff_2' & `mean_sh_2' & `sd_sh_2' & `N_sh_2' & `mean_`weight'_2' & `sd_`weight'_2' & `N_`weight'_2' & `pvalue_sh_2' & `pvalue_`weight'_2' &  `pvalue2_`weight'_2' \\" _n
		file write soutput "Above secondary education & `mean_traff_3' & `sd_traff_3' & `N_traff_3' & `mean_sh_3' & `sd_sh_3' & `N_sh_3' & `mean_`weight'_3' & `sd_`weight'_3' & `N_`weight'_3' & `pvalue_sh_3' & `pvalue_`weight'_3' &  `pvalue2_`weight'_3' \\" _n
		file write soutput "Urban & `mean_traff_4' & `sd_traff_4' & `N_traff_4' & `mean_sh_4' & `sd_sh_4' & `N_sh_4' & `mean_`weight'_4' & `sd_`weight'_4' & `N_`weight'_4' & `pvalue_sh_4' & `pvalue_`weight'_4' &  `pvalue2_`weight'_4' \\" _n
		file write soutput "Assets & `mean_traff_5' & `sd_traff_5' & `N_traff_5' & `mean_sh_5' & `sd_sh_5' & `N_sh_5' & `mean_`weight'_5' & `sd_`weight'_5' & `N_`weight'_5' & `pvalue_sh_5' & `pvalue_`weight'_5' &  `pvalue2_`weight'_5' \\" _n
		file write soutput "Access to electricity & `mean_traff_6' & `sd_traff_6' & `N_traff_6' & `mean_sh_6' & `sd_sh_6' & `N_sh_6' & `mean_`weight'_6' & `sd_`weight'_6' & `N_`weight'_6' & `pvalue_sh_6' & `pvalue_`weight'_6' &  `pvalue2_`weight'_6' \\" _n
	
		file write soutput "\hline\hline" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:}  For DHS data, only the 2008 file is used and it includes sampling weights. Matches are done by region and by year of birth (with the exact year). Columns (4), (5) and (6) provide results from a t-test of the difference in means respectively between columns (1) and (2), columns (1) and (3), and columns (2) and (3). Assets are measured through an index that captures ownership of durable goods (bicycle, car, motorcycle, radio, refrigerator, television). \end{tablenotes} \end{threeparttable} \end{sidewaystable}"
		file close soutput	
	}

	
*** ----------------------------------------------------------------------
**## 						Table A7
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear

global C "edu aboveprimary abovesecondary urban pc1_assets_new electricity"
	
	* Unmatched for shelter, matches (but no weights) for DHS 

		* Trafficked (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if tv2==1 
			local mean_traff_`ll' = r(mean) 
			local sd_traff_`ll' = r(sd) 
			local N_traff_`ll' = r(N)  
			local mean_traff_`ll' : di %8.2f `mean_traff_`ll''
			local sd_traff_`ll' : di %8.2f `sd_traff_`ll''			
			local ll = `ll'+1
			}
			di `mean_traff_1'
			
		* Not trafficked in shelters (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if  tv2==0 & shelter==1  
			local mean_sh_`ll' = r(mean) 
			local sd_sh_`ll' = r(sd) 
			local N_sh_`ll' = r(N)  
			local mean_sh_`ll' : di %8.2f `mean_sh_`ll''
			local sd_sh_`ll' : di %8.2f `sd_sh_`ll''			
			local ll = `ll'+1
			}
			
		* Trafficked vs not trafficked in shelters (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' tv2 if analysis1==1  
			local N_regsh_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue_sh_`ll'  = rtable[4,1] 
			local pvalue_sh_`ll' : di %8.3f `pvalue_sh_`ll''
			local ll = `ll'+1
			}
		
		
	foreach weight in weight_reg_exact weight_prov_2y  {
	
		* Not trafficked in DHS (mean & sd)
		
		local ll = 1
		foreach var in $C {
			summarize `var' if tv2==0 & analysis2_2008==1 & `weight'!=. [aweight=wgt] 
			local mean_`weight'_`ll' = r(mean) 
			local sd_`weight'_`ll' = r(sd) 
			local N_`weight'_`ll' = r(N)  
			local mean_`weight'_`ll' : di %8.2f `mean_`weight'_`ll''
			local sd_`weight'_`ll' : di %8.2f `sd_`weight'_`ll''			
			local ll = `ll'+1
			}
			
		* Trafficked vs not trafficked in DHS (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' tv2 if tv2==1 | (analysis2_2008==1 & `weight'!=.) [pweight=wgt]
			local N_reg1_`weight'_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue_`weight'_`ll' = rtable[4,1] 
			local pvalue_`weight'_`ll' : di %8.3f `pvalue_`weight'_`ll''
			local ll = `ll'+1
			}
			
		* Not trafficked in shelters vs not trafficked in DHS (pvalue)
		
		local ll = 1
		foreach var in $C {
			reg `var' analysis1 if (tv2==0 & shelter==1) | (tv2==0 & analysis2_2008==1 & `weight'!=.) [pweight=wgt] 
			local N_reg2_`weight'_`ll' = e(N)
			matrix rtable = r(table)
			local pvalue2_`weight'_`ll' = rtable[4,1] 
			local pvalue2_`weight'_`ll' : di %8.3f `pvalue2_`weight'_`ll''
			local ll = `ll'+1
			}
	}
	
	
		cap file close soutput
		file open soutput using "output/tables/TableA7.tex", write replace
		file write soutput "\begin{sidewaystable}[htbp] \centering \scriptsize \caption{Socioeconomic background - Comparing matches for DHS} \begin{threeparttable}\begin{tabular}{l | c | c c c | c c c | c c } \hline\hline"  _n
		file write soutput "  &  & \multicolumn{3}{|c|}{Comparison group} & \multicolumn{3}{|c|}{Trafficked vs.} & \multicolumn{2}{|c}{Not trafficked in shelters vs.}\\" _n
		file write soutput " \cline{3-5} \cline{6-8} \cline{9-10}" _n
		file write soutput "   & \multicolumn{1}{c|}{Trafficked} & \multicolumn{1}{c}{Not trafficked}  & \multicolumn{1}{c}{DHS province} & \multicolumn{1}{c}{DHS region} &  \multicolumn{1}{|c}{Not trafficked} & \multicolumn{1}{c}{DHS province} & \multicolumn{1}{c|}{DHS region} & \multicolumn{1}{c}{DHS province} & \multicolumn{1}{c}{DHS region}  \\ " _n
		file write soutput "  & & \multicolumn{1}{c}{in shelters} & \multicolumn{1}{c}{3-year match} & \multicolumn{1}{c}{exact match} &  \multicolumn{1}{|c}{in shelters} & \multicolumn{1}{c}{3-year match} & \multicolumn{1}{c}{exact match}  & \multicolumn{1}{|c}{3-year match}  & \multicolumn{1}{c}{exact match} \\" _n
		file write soutput "   & \multicolumn{1}{c|}{(1)}  & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{|c}{(5)}  &  \multicolumn{1}{c}{(6)} & \multicolumn{1}{c}{(7)}  & \multicolumn{1}{|c}{(8)} & \multicolumn{1}{c}{(9)}    \\ "_n
		file write soutput "   & \multicolumn{1}{c|}{\textit{Mean}}  & \multicolumn{1}{c}{\textit{Mean}}  &  \multicolumn{1}{c}{\textit{Mean}}  &  \multicolumn{1}{c}{\textit{Mean}}  & \multicolumn{1}{|c}{\textit{P-value}}  & \multicolumn{1}{c}{\textit{P-value}}& \multicolumn{1}{c}{\textit{P-value}}& \multicolumn{1}{|c}{\textit{P-value}} & \multicolumn{1}{c}{\textit{P-value}}  \\ " _n
		file write soutput "\hline" _n
	
		file write soutput "Years of education & `mean_traff_1' & `mean_sh_1' & `mean_weight_prov_2y_1' & `mean_weight_reg_exact_1' & `pvalue_sh_1' & `pvalue_weight_prov_2y_1' & `pvalue_weight_reg_exact_1' &  `pvalue2_weight_prov_2y_1'  & `pvalue2_weight_reg_exact_1'\\" _n
		file write soutput "Above primary education & `mean_traff_2' & `mean_sh_2' & `mean_weight_prov_2y_2' & `mean_weight_reg_exact_2' & `pvalue_sh_2' & `pvalue_weight_prov_2y_2'  & `pvalue_weight_reg_exact_2' &  `pvalue2_weight_prov_2y_2'  & `pvalue2_weight_reg_exact_2'\\" _n
		file write soutput "Above secondary education & `mean_traff_3' & `mean_sh_3' & `mean_weight_prov_2y_3' & `mean_weight_reg_exact_3' & `pvalue_sh_3' & `pvalue_weight_prov_2y_3' & `pvalue_weight_reg_exact_3' &  `pvalue2_weight_prov_2y_3'  & `pvalue2_weight_reg_exact_3'\\" _n
		file write soutput "Urban & `mean_traff_4' & `mean_sh_4' & `mean_weight_prov_2y_4'  & `mean_weight_reg_exact_4' & `pvalue_sh_4' & `pvalue_weight_prov_2y_4'  & `pvalue_weight_reg_exact_4' &  `pvalue2_weight_prov_2y_4'  & `pvalue2_weight_reg_exact_4'\\" _n
		file write soutput "Assets & `mean_traff_5' & `mean_sh_5' & `mean_weight_prov_2y_5'  & `mean_weight_reg_exact_5' & `pvalue_sh_5' & `pvalue_weight_prov_2y_5' & `pvalue_weight_reg_exact_5' &  `pvalue2_weight_prov_2y_5'  & `pvalue2_weight_reg_exact_5'\\" _n
		file write soutput "Access to electricity & `mean_traff_6' & `mean_sh_6' & `mean_weight_prov_2y_6' & `mean_weight_reg_exact_6' & `pvalue_sh_6' & `pvalue_weight_prov_2y_6'  & `pvalue_weight_reg_exact_6' &  `pvalue2_weight_prov_2y_6' & `pvalue2_weight_reg_exact_6'\\" _n

		file write soutput "\hline " _n
		file write soutput "Observations & `N_traff_1' & `N_sh_1' & `N_weight_prov_2y_1' & `N_weight_reg_exact_1' & `N_regsh_1' & `N_reg1_weight_prov_2y_1'  & `N_reg1_weight_reg_exact_1' & `N_reg2_weight_prov_2y_1'  & `N_reg2_weight_reg_exact_1' \\" _n

		file write soutput "\hline\hline" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} For DHS data, only the 2008 file is used and it includes sampling weights. Matches are done either by province and by year of birth within a 3-year span, or by region and with the exact year of birth. Columns (5), (6) and (7) provide results from a t-test of the difference in means between column (1) and respectively column (2), (3) or (4). Columns (8) and (9) provide results from a t-test of the difference in means between column (2) and respectively column (3) or (4).Assets are measured through an index that captures ownership of durable goods (bicycle, car, motorcycle, radio, refrigerator, television).  \end{tablenotes} \end{threeparttable} \end{sidewaystable}"
		file close soutput


*** ----------------------------------------------------------------------
**## 						Table A8
*** ----------------------------------------------------------------------


cd "$traffick_repl_local"

use "$traffick_repl_local/input/Trafficking_replication.dta", clear

		
		
		local ll = 1
		foreach var in hhsize sibtot sisters oldersis youngersis livedwithmoth livedwithfath bothbirthparents diffidealgirls1998 order1998 {
			reg `var' tv2 i.dhsregion if sisters!=. & analysis1==1  , ro  
			local beta_c1_r = _b[tv2]
			local sigma_c1_r = _se[tv2]
			local beta_c1_r`ll' : di %8.3f `beta_c1_r'
			local sigma_c1_r`ll' : di %8.3f `sigma_c1_r'
			matrix rtable = r(table)
			local pvalue  = rtable[4,1] 
			local star_c1_r`ll' = ""
				if `pvalue' < 0.1 local star_c1_r`ll'= "*" 
				if `pvalue' < 0.05 local star_c1_r`ll' = "**" 
				if `pvalue' < 0.01 local star_c1_r`ll' = "***" 
			local N_c1_r`ll' = e(N)
			su `var' if e(sample)==1 & tv2==0
			local mcontrol_c1_r = r(mean)
			local mcontrol_c1_r`ll' : di %8.3f `mcontrol_c1_r'
			
			local ll = `ll'+1
		}
	
		* DHS control group (no weights) : loop for type of match
		
		foreach weight in weight_reg_exact   {
			local ll = 1
			foreach var in hhsize sibtot sisters oldersis youngersis livedwithmoth livedwithfath bothbirthparents diffidealgirls1998 order1998 {
				reg `var' tv2 i.dhsregion if sisters!=. & analysis2_2008==1 & `weight'!=. [pweight=wgt], ro   
				local beta_c`weight'_r = _b[tv2]
				local sigma_c`weight'_r = _se[tv2]
				local beta_c`weight'_r`ll' : di %8.3f `beta_c`weight'_r'
				local sigma_c`weight'_r`ll' : di %8.3f `sigma_c`weight'_r'
				matrix rtable = r(table)
				local pvalue  = rtable[4,1] 
				local star_c`weight'_r`ll' = ""
					if `pvalue' < 0.1 local star_c`weight'_r`ll'= "*" 
					if `pvalue' < 0.05 local star_c`weight'_r`ll' = "**" 
					if `pvalue' < 0.01 local star_c`weight'_r`ll' = "***" 
				local N_c`weight'_r`ll' = e(N)
				su `var' if e(sample)==1 & tv2==0
				local mcontrol_c`weight'_r = r(mean)
				local mcontrol_c`weight'_r`ll' : di %8.3f `mcontrol_c`weight'_r'
			
				local ll = `ll'+1
			}
		}
		
		* DHS control group with urban sample only
		
		local ll = 1
			foreach var in hhsize sibtot sisters oldersis youngersis livedwithmoth livedwithfath bothbirthparents diffidealgirls1998 order1998 {
				reg `var' tv2 i.dhsregion if sisters!=. & urban==1 & analysis2_2008==1 & weight_reg_exact!=. [pweight=wgt], ro   
				local beta_cweight_reg_exacturb = _b[tv2]
				local sigma_cweight_reg_exacturb = _se[tv2]
				local beta_cweight_reg_exacturb`ll' : di %8.3f `beta_cweight_reg_exacturb'
				local sigma_cweight_reg_exacturb`ll' : di %8.3f `sigma_cweight_reg_exacturb'
				matrix rtable = r(table)
				local pvalue  = rtable[4,1] 
				local star_cweight_reg_exacturb`ll' = ""
					if `pvalue' < 0.1 local star_cweight_reg_exacturb`ll'= "*" 
					if `pvalue' < 0.05 local star_cweight_reg_exacturb`ll' = "**" 
					if `pvalue' < 0.01 local star_cweight_reg_exacturb`ll' = "***" 
				local N_cweight_reg_exacturb`ll' = e(N)
				su `var' if e(sample)==1 & tv2==0
				local mcontrol_cweight_reg_exacturb = r(mean)
				local mcontrol_cweight_reg_exacturb`ll' : di %8.3f `mcontrol_cweight_reg_exacturb'
			
				local ll = `ll'+1
			}
			
	cap file close soutput
		file open soutput using "output/tables/TableA8.tex", write replace
		file write soutput "\begin{table}[htbp] \centering \scriptsize \caption{Household composition - DHS comparison group, exact matches at the region level} \begin{threeparttable} \begin{tabular}{lcccccc} \\[-1.8ex] \hline\hline \\[-1.8ex]"  _n
		file write soutput "& \multicolumn{3}{c}{Full sample} & \multicolumn{3}{c}{Urban sample}\\" _n
		file write soutput "\\[-1.8ex] \cmidrule(r){2-4} \cmidrule(l){5-7}  \\[-1.8ex]" _n
		file write soutput "& (1) & (2) & (3) & (4) & (5) & (6) \\   " _n
		file write soutput "  \textit{Dependent variables:}  & Trafficked (OLS)  & Not trafficked (mean) & Obs. & Trafficked (OLS)  & Not trafficked (mean) & Obs.\\ "_n
		file write soutput "\\[-1.8ex]\hline\\[-1.8ex]"
		
		file write soutput "Household size & `beta_cweight_reg_exact_r1'`star_cweight_reg_exact_r1' & `mcontrol_cweight_reg_exact_r1' & `N_cweight_reg_exact_r1' & `beta_cweight_reg_exacturb1'`star_cweight_reg_exacturb1' & `mcontrol_cweight_reg_exacturb1' & `N_cweight_reg_exacturb1'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r1') & & & (`sigma_cweight_reg_exacturb1')\\ " _n
		file write soutput "Number of siblings & `beta_cweight_reg_exact_r2'`star_cweight_reg_exact_r2' & `mcontrol_cweight_reg_exact_r2' & `N_cweight_reg_exact_r2' & `beta_cweight_reg_exacturb2'`star_cweight_reg_exacturb2' & `mcontrol_cweight_reg_exacturb2' & `N_cweight_reg_exacturb2'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r2') & & & (`sigma_cweight_reg_exacturb2')\\ " _n
		file write soutput "Number of sisters & `beta_cweight_reg_exact_r3'`star_cweight_reg_exact_r3' & `mcontrol_cweight_reg_exact_r3' & `N_cweight_reg_exact_r3' & `beta_cweight_reg_exacturb3'`star_cweight_reg_exacturb3' & `mcontrol_cweight_reg_exacturb3' & `N_cweight_reg_exacturb3'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r3') & & & (`sigma_cweight_reg_exacturb3')\\ " _n
		file write soutput "Number of older sisters & `beta_cweight_reg_exact_r4'`star_cweight_reg_exact_r4' & `mcontrol_cweight_reg_exact_r4' & `N_cweight_reg_exact_r4' & `beta_cweight_reg_exacturb4'`star_cweight_reg_exacturb4' & `mcontrol_cweight_reg_exacturb4' & `N_cweight_reg_exacturb4'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r4') & & & (`sigma_cweight_reg_exacturb4')\\ " _n
		file write soutput "Number of younger sisters & `beta_cweight_reg_exact_r5'`star_cweight_reg_exact_r5' & `mcontrol_cweight_reg_exact_r5' & `N_cweight_reg_exact_r5' & `beta_cweight_reg_exacturb5'`star_cweight_reg_exacturb5' & `mcontrol_cweight_reg_exacturb5' & `N_cweight_reg_exacturb5'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r5') & & & (`sigma_cweight_reg_exacturb5')\\ " _n
		file write soutput "Lived with birth mother & `beta_cweight_reg_exact_r6'`star_cweight_reg_exact_r6' & `mcontrol_cweight_reg_exact_r6' & `N_cweight_reg_exact_r6' & `beta_cweight_reg_exacturb6'`star_cweight_reg_exacturb6' & `mcontrol_cweight_reg_exacturb6' & `N_cweight_reg_exacturb6'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r6') & & & (`sigma_cweight_reg_exacturb6')\\ " _n
		file write soutput "Lived with birth father & `beta_cweight_reg_exact_r7'`star_cweight_reg_exact_r7' & `mcontrol_cweight_reg_exact_r7' & `N_cweight_reg_exact_r7' & `beta_cweight_reg_exacturb7'`star_cweight_reg_exacturb7' & `mcontrol_cweight_reg_exacturb7' & `N_cweight_reg_exacturb7'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r7') & & & (`sigma_cweight_reg_exacturb7')\\ " _n
		file write soutput "Lived with both birth parents & `beta_cweight_reg_exact_r8'`star_cweight_reg_exact_r8' & `mcontrol_cweight_reg_exact_r8' & `N_cweight_reg_exact_r8' & `beta_cweight_reg_exacturb8'`star_cweight_reg_exacturb8' & `mcontrol_cweight_reg_exacturb8' & `N_cweight_reg_exacturb8'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r8') & & & (`sigma_cweight_reg_exacturb8')\\ " _n
		file write soutput "Deviation from ideal no. of girls & `beta_cweight_reg_exact_r9'`star_cweight_reg_exact_r9' & `mcontrol_cweight_reg_exact_r9' & `N_cweight_reg_exact_r9' & `beta_cweight_reg_exacturb9'`star_cweight_reg_exacturb9' & `mcontrol_cweight_reg_exacturb9' & `N_cweight_reg_exacturb9'\\" _n
		file write soutput "& (`sigma_cweight_reg_exact_r9') & & & (`sigma_cweight_reg_exacturb9')\\ " _n
		file write soutput "Respondent's birth order higher & `beta_cweight_reg_exact_r10'`star_cweight_reg_exact_r10' & `mcontrol_cweight_reg_exact_r10' & `N_cweight_reg_exact_r10' & `beta_cweight_reg_exacturb10'`star_cweight_reg_exacturb10' & `mcontrol_cweight_reg_exacturb10' & `N_cweight_reg_exacturb10'\\" _n
		file write soutput "than ideal no. of girls & (`sigma_cweight_reg_exact_r10') & & & (`sigma_cweight_reg_exacturb10')\\ " _n

	
		file write soutput "\\[-1.8ex]\hline\hline\\[-1.8ex]" _n
		file write soutput "\end{tabular} \begin{tablenotes} \footnotesize \item \textit{Notes:} Columns 1 and 4 report the results of an OLS regression of each dependent variable on the trafficked status and each row is the result of a different regression. Columns 2 and 5 report the mean of each dependent variable in the corresponding comparison group. For all specifications, region fixed effects are included. There are no other controls. Only DHS observations matching victims' regions and exact years of birth are kept. For each dependent variable (in rows), a first specification is estimated on the full sample and another one only on the sample of urban observations. Robust standard errors in parentheses. *, ** and *** indicate significance at the 10, 5, 1\% levels." _n
		file write soutput "\end{tablenotes} \end{threeparttable} \end{table}"
		file close soutput	
